mysql加载数据本地infile
我正在尝试使用下面的代码使用 LOAD DATA LOCAL INFILE 将数据加载到 mysql 表中。
Mysql:
LOAD DATA INFILE '/var/www/vhosts/domain.com/httpdocs/test1.csv' INTO TABLE temp_table FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (recloc,client_acc)
编辑:将 LOAD DATA LOCAL INFILE 更改为 LOADA DATA INFILE,删除 SET id=null,添加 IGNORE 1 LINES
我没有收到任何错误,也没有导入记录。我相信这个问题与列名称有关,但我很难完全理解这些名称应该是什么。它们应该是 CSV 中的实际列名称吗?或者数据库表中的字段名称?我还希望有一个自动递增的主键(id)。
CSV:
recloc,client_acc
"NLGSX3","CORPORATE"
"7SC3BA","QUALITY ASSURANCE"
"3B9OHF","90717-6710"
对我可能做错的事情有什么建议吗?谢谢!
I'm trying to load data into a mysql table using LOAD DATA LOCAL INFILE using the code below.
Mysql:
LOAD DATA INFILE '/var/www/vhosts/domain.com/httpdocs/test1.csv' INTO TABLE temp_table FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (recloc,client_acc)
Edit: changed LOAD DATA LOCAL INFILE to LOADA DATA INFILE, removed SET id=null, added IGNORE 1 LINES
I'm getting no errors and no imported records. I believe the issue is related to the column names but i'm having a hard time fully understanding what those names should be. Should they be the actual column names within the CSV? or the field names in the DB Table? I would also like the have an auto_incremented primary key (id).
CSV:
recloc,client_acc
"NLGSX3","CORPORATE"
"7SC3BA","QUALITY ASSURANCE"
"3B9OHF","90717-6710"
Any suggestions to what I may be doing wrong? thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CSV 中的列名称不是必需的,因此您应该添加
IGNORE 1 LINES
子句。查询
(recloc,client_acc)
中的列需要与表中的列匹配。CSV 中的第一列将插入到
recloc
中,第二列插入到client_acc
中。如果语句中没有指定 AUTO_INCRMENT 列,但表中有一个,则应该自动填充。
Column names in CSV are not necessary, so you should add
IGNORE 1 LINES
clause.Columns in your query
(recloc,client_acc)
need to match columns in table.First column from CSV will be inserted into
recloc
, second intoclient_acc
.If you don't specifu AUTO_INCREMENT column in the statement, but there is one in the table, it should fill automatically.
用于 excel 到 mysql 数据导入的简短而甜蜜的解决方案:
适用于 txt 文件格式。
详细信息:
text.txt 文件 <<== 此文本文件第一行表列名称:
请忽略下一行语句
wamp 中的 SQL 查询
为了成功运行此命令,我们单独创建了文件夹。
真实的路径是
C:\wamp\mysql\data\wamp\www\touch\text.txt <<==pysical 文件路径是。
但我们提到c:/wamp/touch/text.txt
Short and sweet solution for excel to mysql data import:
Working good for txt file formats.
IN DETAIL:
text.txt file <<== this text file first lines table column names:
pls ignore next line statements
SQL query in wamp
For this commnad run successfully we have create folders for separately.
Real one is
C:\wamp\mysql\data\wamp\www\touch\text.txt <<==pysical file path is.
But we mention c:/wamp/touch/text.txt