我正在尝试在表格中导入经典城市列表。我在AWS RDS上使用Mysql 5.7.22-log。 这是表DDL:
CREATE TABLE `city` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`createdBy` varchar(255) DEFAULT NULL,
`createdDate` datetime NOT NULL,
`lastModifiedBy` varchar(255) DEFAULT NULL,
`lastModifiedDate` datetime DEFAULT NULL,
`sid` varchar(36) NOT NULL,
`version` bigint(20) NOT NULL,
`country` varchar(2) NOT NULL,
`district` varchar(255) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`region` varchar(255) DEFAULT NULL,
`zipCode` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_i22k5i5v70edpr8sn0f7qsqu8` (`sid`),
UNIQUE KEY `UKprra9tj5gtk21kc3chb9skup9` (`name`,`district`,`country`)
) ENGINE=InnoDB AUTO_INCREMENT=8192 DEFAULT CHARSET=utf8
我有一个UTF-8 .csv文件,如下所示:
name;district;zipCode;region;country
Abano Terme;PD;35031;Veneto;IT
Abbadia Cerreto;LO;26834;Lombardia;IT
Abbadia Lariana;LC;23821;Lombardia;IT
Abbadia San Salvatore;SI;53021;Toscana;IT
我以这种方式导入数据:
LOAD DATA LOCAL INFILE 'C:\\City.csv' INTO TABLE City FIELDS TERMINATED BY ';' IGNORE 1 LINES
(NAME,district,zipCode,region,country)
SET `createdBy`='system',createdDate=NOW(),lastModifiedBy='system',lastModifiedDate=NOW(),sid=UUID(),`version`=1;
数据已导入,但是我对截断的数据有很多警告:
1 queries executed, 1 success, 0 errors, 1 warnings
Query: LOAD DATA LOCAL INFILE 'C:\\City.csv' INTO TABLE City FIELDS TERMINATED BY ';' IGNORE 1 LINES (n...
8103 row(s) affected, 8100 warning(s)
Execution Time : 0.309 sec
Transfer Time : 0.002 sec
Total Time : 0.312 sec
Note Code : 1265
Data truncated for column 'country' at row 1
Note Code : 1265
Data truncated for column 'country' at row 2
Note Code : 1265
Data truncated for column 'country' at row 3
Note Code : 1265
Data truncated for column 'country' at row 4
Note Code : 1265
Data truncated for column 'country' at row 5
Note Code : 1265
Data truncated for column 'country' at row 6
Note Code : 1265
Data truncated for column 'country' at row 7
我不明白为什么,在csv文件中,contry值为2个字符。
我在做什么错了?
答案 0 :(得分:0)
如果我想清楚地告诉您,则需要在“城市”表中将country
属性的长度更改为两个以上,如下所示。
`country` varchar(50) NOT NULL,
答案 1 :(得分:0)
您是否查看了加载了哪些数据?
默认情况下,LOAD DATA
假定行以换行符终止,但是MSWindows(从MS-DOS继承,从CPM继承)使用回车符和换行符作为换行符。这样就可以看到:
name;district;zipCode;region;country\r
Abano Terme;PD;35031;Veneto;IT\r
Abbadia Cerreto;LO;26834;Lombardia;IT\r
Abbadia Lariana;LC;23821;Lombardia;IT\r
Abbadia San Salvatore;SI;53021;Toscana;IT\r
尝试:
LOAD DATA LOCAL INFILE 'C:\\City.csv'
INTO TABLE City
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(NAME,district,zipCode,region,country)
SET `createdBy`='system'
,createdDate=NOW()
,lastModifiedBy='system'
,lastModifiedDate=NOW()
,sid=UUID()
,`version`=1;