Importing a csv into mysql via command line(通过命令行将 csv 导入 mysql)
问题描述
我正在尝试将一个非常大的 .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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过命令行将 csv 导入 mysql


基础教程推荐
- 从字符串 TSQL 中获取数字 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01