批量插入mysql(CSV文件 - Codeigniter)

时间:2011-01-20 19:01:37

标签: csv

我需要将批量插入类别的函数或代码放入mysql数据库。我正在为我的项目使用codeigniter。

1 个答案:

答案 0 :(得分:1)

START TRANSACTION;

DELETE FROM `mytable`;

LOAD DATA INFILE '/var/www/something.csv'
INTO TABLE `mytable`
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY ''
LINES TERMINATED BY '\r\n'
(email, login, pass)

COMMIT;

这可以直接在mysql中运行,以便从CSV导入数据