尝试将csv格式的货币导入数据库时出错:
LOAD DATA LOW_PRIORITY LOCAL INFILE 'C:\\currencies.csv'
INTO TABLE `test`.`currencies`
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"'
LINES TERMINATED BY '\r\n' IGNORE 1 LINES
(`alpha3`, `number`, `decimals`, `name`, `countries`);
示例csv:
alpha3,number,decimals,name,countries
AED,784,2,"United Arab Emirates dirham","[""ARE""]"
AFN,971,2,"Afghan afghani","[""AFG""]"
ALL,008,2,"Albanian lek","[""ALB""]"
AMD,051,2,"Armenian dram","[""ARM""]"
我认为是因为国家领域。
创建表格的脚本:
CREATE TABLE `currencies` (
`alpha3` CHAR(3) NOT NULL,
`number` CHAR(3) NULL DEFAULT NULL,
`decimals` TINYINT(1) NULL DEFAULT NULL,
`name` VARCHAR(50) NULL DEFAULT NULL,
`countries` TEXT NULL,
PRIMARY KEY (`alpha3`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
答案 0 :(得分:0)
适合我:
mysql> LOAD DATA LOW_PRIORITY LOCAL INFILE 'C:\\Temp\\currencies.csv'
-> INTO TABLE `try`.`currencies`
-> FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"'
-> LINES TERMINATED BY '\r\n' IGNORE 1 LINES
-> (`alpha3`, `number`, `decimals`, `name`, `countries`);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from currencies;
+--------+--------+----------+-----------------------------+-----------+
| alpha3 | number | decimals | name | countries |
+--------+--------+----------+-----------------------------+-----------+
| AED | 784 | 2 | United Arab Emirates dirham | ["ARE"] |
| AFN | 971 | 2 | Afghan afghani | ["AFG"] |
| ALL | 008 | 2 | Albanian lek | ["ALB"] |
| AMD | 051 | 2 | Armenian dram | ["ARM"] |
+--------+--------+----------+-----------------------------+-----------+
4 rows in set (0.00 sec)
我在Windows上使用5.6.12版。您使用的是什么版本和操作系统? (我怀疑版本是否重要。)