简体   繁体   English

MySQL加载数据infile连接列

[英]MySQL load data infile concatenate columns

I have a table like this 我有这样的桌子

mytable(`id` int, `text` varchar(255))

Also I have cvs-like file 我也有类似cvs的文件

1 hello word
2 this is a test

They are separated by space(or something else) 它们被空间(或其他东西)隔开

So can I use LOAD DATA INFILE to load the file into the table? 那么我可以使用LOAD DATA INFILE将文件加载到表中吗? How can I do this..? 我怎样才能做到这一点..?

I would probably go for 2 tables... One is the final, the other has 2 fields just as your CSV. 我可能会去2个表...一个是决赛,另一个有2个字段,就像您的CSV一样。

First solution, in file followed by insert into table2 select concat(field1, field2) from table1 第一种解决方案,在文件中,然后插入到table2中,从table1中选择concat(field1,field2)

The other solution is to automate the solution 1 using a trigger. 另一种解决方案是使用触发器使解决方案1自动化。 I'm not sure you can trigger something at the end, so trigger for each line added... 我不确定您是否可以在结束时触发某些内容,因此请为添加的每一行触发...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM