mysqlimport - Import CSV File in MS Windows XAMPP emvironment

╄→尐↘猪︶ㄣ 提交于 2020-01-04 06:58:00

问题


I am trying to import a CSV file from to a mysql database from the command line. This will be later incorporated into a Windows batch file.

mysqlimport -u user -puserpw --columns=ID,CID,Alerted --fields-terminated-by=',' --local School Customer.csv  

All the data loads into the first column in the Customer table. I want to correctly import data from the CSV to the appropriate column.

CSV Data format:

ID,CID,Alerted
1,CS,N
2,CS,N
3,CS,N

I would like to use mysqlimport since this will be easier to add to a Windows batch file. How can I do this please help?


回答1:


I guess you have to add --lines-terminated-by='\n' with mysqlimport. I run a quick test here and worked.

mysqlimport --local --ignore-lines=1 --fields-terminated-by=',' --lines-terminated-by='\n' db_name table_name.csv



回答2:


I had to enclose the values in double quotes "

mysqlimport -u user -puserpw --columns=ID,CID,Alerted  --ignore-lines=1 --fields-terminated-by="," --lines-terminated-by="\n" --local School Customer.csv  

That fixed it.




回答3:


Try to use the complete description for importing the csv file like :

fields terminated by ',' enclosed by '"' lines terminated by '\n'

Thanks



来源:https://stackoverflow.com/questions/23002443/mysqlimport-import-csv-file-in-ms-windows-xampp-emvironment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!