mysql加载数据本地infile

发布于 2024-10-08 05:42:49 字数 653 浏览 0 评论 0原文

我正在尝试使用下面的代码使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄居人 2024-10-15 05:42:49

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 into client_acc.

If you don't specifu AUTO_INCREMENT column in the statement, but there is one in the table, it should fill automatically.

泅人 2024-10-15 05:42:49

用于 excel 到 mysql 数据导入的简短而甜蜜的解决方案:

适用于 txt 文件格式。
详细信息:

tbl name=t1
feilds are= name varchar,email varchar;

text.txt 文件 <<== 此文本文件第一行表列名称:

name,   email
"n1",   "e1"  next line 
"n2",   "e2" next line 
"n3",   "e3" next line 
"n4",   "e4" next line 
"n5",   "e5" next line 
"n6",   "e6" next line 
"n7",   "e7" next line 

请忽略下一行语句
wamp 中的 SQL 查询

LOAD DATA INFILE 'c:/wamp/www/touch/text.txt' INTO TABLE t1 FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES(name,email)

为了成功运行此命令,我们单独创建了文件夹。

真实的路径是

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:

tbl name=t1
feilds are= name varchar,email varchar;

text.txt file <<== this text file first lines table column names:

name,   email
"n1",   "e1"  next line 
"n2",   "e2" next line 
"n3",   "e3" next line 
"n4",   "e4" next line 
"n5",   "e5" next line 
"n6",   "e6" next line 
"n7",   "e7" next line 

pls ignore next line statements
SQL query in wamp

LOAD DATA INFILE 'c:/wamp/www/touch/text.txt' INTO TABLE t1 FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES(name,email)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文