问题描述
我正在尝试将一个非常大的 .csv 文件 (~4gb) 导入 mysql.我正在考虑使用 phpmyadmin,但是您的最大上传大小为 2mb.有人告诉我,我必须使用命令行.
I'm trying to import a very large .csv file (~4gb) into mysql. I was considering using phpmyadmin, but then you have a max upload size of 2mb. Someone told me that I have to use the command line.
我打算使用这些说明来导入它:http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html#c5680
I was going to use these directions to import it: http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html#c5680
将 .csv 表中的第一行设置为 mysql 表中的列名的命令是什么?此选项可通过 phpmyadmin 获得,因此它们也必须是 mysql 命令行版本,对吗?请帮我.谢谢.
What would be the command to set the first row in the .csv table as the column names in the mysql table? This option is available through phpmyadmin, so their must be a mysql command line version too, right?. Please help me. Thank you.
-拉杰
推荐答案
试试这个命令
load data local infile 'file.csv' into table table
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(column1, column2, column3,...)
这里的字段是数据需要放在的实际表字段.括起来和终止的行是可选的,如果您有用双引号括起来的列,例如 Excel 导出等,可以提供帮助.
The fields here are the actual table fields that the data needs to sit in. The enclosed by and lines terminated by are optional and can help if you have columns enclosed with double-quotes such as Excel exports, etc.
有关详细信息,请查看手册.
For further details check the manual.
要将第一行设置为表列名称,只需忽略读取的行并在命令中添加值.
For setting the first row as the table column names, just ignore the row from being read and add the values in the command.
这篇关于通过命令行将 csv 导入 mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!