Mysql导入表插入查询

时间:2014-03-30 06:34:58

标签: mysql

文件字符串(插入...)超过500k。 如何仅使用插入查询导入表数据? 样品(超过500k行)

INSERT INTO test(id, tag, group_id, photo_id, user_id, info) VALUES (555, 'city', 4444, 137187954, 67647144, 'ddddd');
INSERT INTO test(id, tag, group_id, photo_id, user_id, info) VALUES (444, 'city', 4444, 137187954, 67647144, 'fffff');
INSERT INTO test(id, tag, group_id, photo_id, user_id, info) VALUES (333, 'city', 4444, 137187954, 67647144, 'fffff');

表:

create table test(
id int,
tag varchar(25),
user_id int,
photo_id int,
group_id int,
info varchar(256))

在表格中加载文件:

mysql> load data local infile "E:/output00000.txt" into table test;
Query OK, 589975 rows affected, 65535 warnings (17.31 sec)
Records: 589975  Deleted: 0  Skipped: 0  Warnings: 3539850

mysql> select count(*) from test;
+----------+
| count(*) |
+----------+
|   589975 |
+----------+
1 row in set (0.68 sec)

mysql> select * from test limit 500, 5;
+------+------+---------+----------+----------+------+
|  id  | tag  | user_id | photo_id | group_id | info |
+------+------+---------+----------+----------+------+
|    0 | NULL |    NULL |     NULL |     NULL | NULL |
|    0 | NULL |    NULL |     NULL |     NULL | NULL |
|    0 | NULL |    NULL |     NULL |     NULL | NULL |
|    0 | NULL |    NULL |     NULL |     NULL | NULL |
|    0 | NULL |    NULL |     NULL |     NULL | NULL |
+------+------+---------+----------+----------+------+
5 rows in set (0.00 sec)

ANSWER

将数据更改为:

555 city    4444    137187954   67647144    ddddd
444 city    4444    137187954   67647144    fffff
333 city    4444    137187954   67647144    fffff

执行后:

LOAD DATA LOCAL INFILE "PATH" INTO TABLE test FIELDS TERMINATED BY "\t" LINES TERMINATED BY "\n" (columns)
每百万行约20-30分钟。

1 个答案:

答案 0 :(得分:0)

您可以使用逗号并提供另一个要插入的值列表:

INSERT INTO tableA (col1, col2, col3)
VALUES (val1, val2, val3)
     , (val4, val5, val6)
     , (val7, val8, val9)