更新时间:2023-11-30 19:27:10
不要自动认为您的服务器设置有误.默认设置可能很好.即使在旧机器上,插入10000行也应该是小菜一碟,但这取决于您如何进行插入.
Don't automatically assume that your server settings are wrong. The default settings are probably fine. Inserting 10000 rows should be a piece of cake, even on an old machine, but it depends on how you do your inserts.
在这里,我将介绍3种插入数据的方法,从慢到快:
Here I'll describe 3 methods for inserting data, ranging from slow to fast:
如果要插入许多行,则以下操作非常慢:
The following is extremely slow if you have many rows to insert:
INSERT INTO mytable (id,name) VALUES (1,'Wouter');
INSERT INTO mytable (id,name) VALUES (2,'Wouter');
INSERT INTO mytable (id,name) VALUES (3,'Wouter');
这已经快得多了:
INSERT INTO mytable (id, name) VALUES
(1, 'Wouter'),
(2, 'Wouter'),
(3, 'Wouter');
(语法错误)
通常这是最快的:
具有如下所示的CSV文件:
Have CSV file that looks like this:
1,Wouter
2,Wouter
3,Wouter
然后运行类似
LOAD DATA FROM INFILE 'c:/temp.csv' INTO TABLE mytable
您使用哪种上述方法?