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


- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01