为什么无法将数据加载到 mysql:
Why can't load the data into mysql:
Mysql table price
结构:
CREATE TABLE `price` (
`code` varchar(12) ,
`date` date ,
`open` decimal(8,2) ,
`high` decimal(8,2) ,
`low` decimal(8,2) ,
`close` decimal(8,2) ,
`amount` decimal(20,2) ,
`volume` decimal(16,2)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
这是我要加载到表格价格中的 data.csv 文件。
000046.XSHE,19940912,20.0,20.0,16.0,16.92,121262592.0,7043300
000046.XSHE,19940913,17.0,17.32,16.0,16.46,47195860.0,2810800
000046.XSHE,19940914,16.3,16.4,15.49,15.95,24762992.0,1558300
音量最大值为 47195860.0
,在 decimal(20,2)
范围内。
使用 mysql load
命令加载。
LOAD DATA local INFILE 'data.csv'
INTO TABLE finance.price
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
lines terminated by '\r\n';
出现错误信息:
Query OK, 1 row affected, 1 warning (0.09 sec)
Records: 1 Deleted: 0 Skipped: 0 Warnings: 1
显示它以了解原因。
show warnings;
+---------+------+---------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------+
| Warning | 1265 | Data truncated for column 'volume' at row 1 |
+---------+------+---------------------------------------------+
1 row in set (0.00 sec)
编号 121262592.0
比 decimal(20,2)
低那么多,为什么 Data truncated for column 'volume' at row 1
,只加载了一行。
select * from price;
+-------------+------------+-------+-------+-------+-------+--------------+------------+
| code | date | open | high | low | close | amount | volume |
+-------------+------------+-------+-------+-------+-------+--------------+------------+
| 000046.XSHE | 1994-09-12 | 20.00 | 20.00 | 16.00 | 16.92 | 121262592.00 | 7043300.00 |
+-------------+------------+-------+-------+-------+-------+--------------+------------+
1 row in set (0.00 sec)
LOAD DATA local INFILE 'data.csv'
INTO TABLE finance.price
FIELDS TERMINATED BY ','
OPTIONAL ENCLOSED BY '"'
lines terminated by '\r\n';
Mysql table price
结构:
CREATE TABLE `price` (
`code` varchar(12) ,
`date` date ,
`open` decimal(8,2) ,
`high` decimal(8,2) ,
`low` decimal(8,2) ,
`close` decimal(8,2) ,
`amount` decimal(20,2) ,
`volume` decimal(16,2)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
这是我要加载到表格价格中的 data.csv 文件。
000046.XSHE,19940912,20.0,20.0,16.0,16.92,121262592.0,7043300
000046.XSHE,19940913,17.0,17.32,16.0,16.46,47195860.0,2810800
000046.XSHE,19940914,16.3,16.4,15.49,15.95,24762992.0,1558300
音量最大值为 47195860.0
,在 decimal(20,2)
范围内。
使用 mysql load
命令加载。
LOAD DATA local INFILE 'data.csv'
INTO TABLE finance.price
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
lines terminated by '\r\n';
出现错误信息:
Query OK, 1 row affected, 1 warning (0.09 sec)
Records: 1 Deleted: 0 Skipped: 0 Warnings: 1
显示它以了解原因。
show warnings;
+---------+------+---------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------+
| Warning | 1265 | Data truncated for column 'volume' at row 1 |
+---------+------+---------------------------------------------+
1 row in set (0.00 sec)
编号 121262592.0
比 decimal(20,2)
低那么多,为什么 Data truncated for column 'volume' at row 1
,只加载了一行。
select * from price;
+-------------+------------+-------+-------+-------+-------+--------------+------------+
| code | date | open | high | low | close | amount | volume |
+-------------+------------+-------+-------+-------+-------+--------------+------------+
| 000046.XSHE | 1994-09-12 | 20.00 | 20.00 | 16.00 | 16.92 | 121262592.00 | 7043300.00 |
+-------------+------------+-------+-------+-------+-------+--------------+------------+
1 row in set (0.00 sec)
LOAD DATA local INFILE 'data.csv'
INTO TABLE finance.price
FIELDS TERMINATED BY ','
OPTIONAL ENCLOSED BY '"'
lines terminated by '\r\n';