我创建了一个名为StatesandCities的表,其中包含 3 列:CountryCode(它的外键)、State和City,如下所示:
create table StatesandCities (CountryCode varchar(2), State varchar(20), city varchar(20),foreign key (CountryCode) references ListOfCountries (CountryCode));
我有一个包含所有值的 .CSV 文件:
CountryCode,State,City
IN,Karnataka,Bangalore
IN,Karnataka,Mysore
IN,Karnataka,Tumkur
IN,Maharashtra,Mumbai
IN,Maharashtra,Thane
IN,Maharashtra,Nasik
GB,Yorkshire,County Hill
GB,SouthWales,Murrey
这正是它在 Excel 工作表中的表现:
CountryCode State City
IN Karnataka Bangalore
IN Karnataka Mysore
IN Karnataka Tumkur
IN Maharashtra Mumbai
IN Maharashtra Thane
IN Maharashtra Nasik
GB Yorkshire County Hill
GB SouthWales Murrey
我使用此代码在 MySQL 5.6 命令行客户端中输入 CSV 文件:
LOAD DATA LOCAL INFILE 'H:/Statesncities.csv' INTO TABLE StatesandCities FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' ignore 1 lines (CountryCode, State, City);
正在输入这些值,但它们不是我需要的正确表格格式。而且,如果数据值很长,它也会被削减。一切都搞混了:我尝试过更改屏幕大小、页面布局,但似乎没有任何效果。
输出: