mysql迅速制造大批数据,复制一个表中的(部分或全部)数据到另一个表中。
用法:INSERT INTO table_name1 (field1,field2) SELECT field1,field2 FROM table_name2;
前提条件
代码如下 | 复制代码 |
MySQL CREATE TABLE `user` ( |
查看一下结构,更直观
代码如下 | 复制代码 |
mysql> desc user; 插入原始数据 MySQL mysql> INSERT INTO `user`(`username`,`password`) VALUES ('hello','123456'),('twitter','123456'),('baidu','123456'),('google','123456'),('facebook','123456'),('linux','123456'),('cisco','123456'),('huawei','123456'),('lenovo','123456'),('apple','123456'),('oracle','123456'),('sun','123456'); 复制数据到历史表 MySQL
|
附加mysql大批量复制数据,时间变化:
在自己的电脑上测试(Ubuntu14.04 LTS 64位 + xampp),前3000条数据速度比较快,3000条以后执行时间成倍增加,2万5千条数据执行时间1分钟。314万数据,两分29秒
代码如下 | 复制代码 |
mysql> insert into user(username,password) select username,password from user; mysql> insert into user(username,password) select username,password from user; mysql> insert into user(username,password) select username,password from user; mysql> insert into user(username,password) select username,password from user; mysql> insert into user(username,password) select username,password from user; mysql> insert into user(username,password) select username,password from user; mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ Query OK, 1536 rows affected, 1 warning (0.15 sec) mysql> mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ mysql> insert into user(username,password) select username,password from user;\ |