热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

简单记录mysql中inserintoselect语句测试_MySQL

简单记录mysql中inserintoselect语句测试
mysql迅速制造大批数据,复制一个表中的(部分或全部)数据到另一个表中。

用法:INSERT INTO table_name1 (field1,field2) SELECT field1,field2 FROM table_name2;

前提条件

CREATE TABLE `user` (`id` int(10) NOT NULL AUTO_INCREMENT,`username` varchar(30) NOT NULL,`password` char(32) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE `user_his` (`his_id` int(10) NOT NULL AUTO_INCREMENT,`id` int(10) NOT NULL,`username` varchar(30) NOT NULL,`password` char(32) NOT NULL,PRIMARY KEY (`his_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATETABLE`user`(

`id`int(10)NOT NULLAUTO_INCREMENT,

`username`varchar(30)NOT NULL,

`password`char(32)NOT NULL,

PRIMARY KEY(`id`)

)ENGINE=InnoDBDEFAULTCHARSET=utf8;

CREATETABLE`user_his`(

`his_id`int(10)NOT NULLAUTO_INCREMENT,

`id`int(10)NOT NULL,

`username`varchar(30)NOT NULL,

`password`char(32)NOT NULL,

PRIMARY KEY(`his_id`)

)ENGINE=InnoDBDEFAULTCHARSET=utf8;

mysql> desc user;+----------+-------------+------+-----+---------+----------------+| Field| Type| Null | Key | Default | Extra|+----------+-------------+------+-----+---------+----------------+| id | int(10) | NO | PRI | NULL| auto_increment || username | varchar(30) | NO | | NULL||| password | char(32)| NO | | NULL||+----------+-------------+------+-----+---------+----------------+3 rows in set (0.00 sec)mysql> desc user_his;+----------+-------------+------+-----+---------+----------------+| Field| Type| Null | Key | Default | Extra|+----------+-------------+------+-----+---------+----------------+| his_id | int(10) | NO | PRI | NULL| auto_increment || id | int(10) | NO | | NULL||| username | varchar(30) | NO | | NULL||| password | char(32)| NO | | NULL||+----------+-------------+------+-----+---------+----------------+4 rows in set (0.01 sec)

mysql>descuser;

+----------+-------------+------+-----+---------+----------------+

|Field |Type |Null|Key|Default|Extra |

+----------+-------------+------+-----+---------+----------------+

|id |int(10) |NO |PRI|NULL |auto_increment|

|username|varchar(30)|NO | |NULL | |

|password|char(32) |NO | |NULL | |

+----------+-------------+------+-----+---------+----------------+

3rowsinset(0.00sec)

mysql>descuser_his;

+----------+-------------+------+-----+---------+----------------+

|Field |Type |Null|Key|Default|Extra |

+----------+-------------+------+-----+---------+----------------+

|his_id |int(10) |NO |PRI|NULL |auto_increment|

|id |int(10) |NO | |NULL | |

|username|varchar(30)|NO | |NULL | |

|password|char(32) |NO | |NULL | |

+----------+-------------+------+-----+---------+----------------+

4rowsinset(0.01sec)

插入原始数据

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>INSERTINTO`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> INSERT INTO `user_his`(`id`,`username`,`password`) select `id`,`username`,`password` from `user`;

mysql>INSERTINTO`user_his`(`id`,`username`,`password`)select`id`,`username`,`password`from`user`;

附加mysql大批量复制数据,时间变化:

在自己的电脑上测试(Ubuntu14.04 LTS 64位 + xampp),前3000条数据速度比较快,3000条以后执行时间成倍增加,2万5千条数据执行时间1分钟。314万数据,两分29秒

mysql> insert into user(username,password) select username,password from user;

Query OK, 12 rows affected, 1 warning (0.07 sec)

Records: 12 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;

Query OK, 24 rows affected, 1 warning (0.08 sec)

Records: 24 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;

Query OK, 48 rows affected, 1 warning (0.11 sec)

Records: 48 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;

Query OK, 96 rows affected, 1 warning (0.10 sec)

Records: 96 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;

Query OK, 192 rows affected, 1 warning (0.10 sec)

Records: 192 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;

Query OK, 384 rows affected, 1 warning (0.10 sec)

Records: 384 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 768 rows affected, 1 warning (0.13 sec)

Records: 768 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 1536 rows affected, 1 warning (0.15 sec)Records: 1536 Duplicates: 0 Warnings: 1

mysql>

mysql> insert into user(username,password) select username,password from user;/

Query OK, 3072 rows affected, 1 warning (0.17 sec)

Records: 3072 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 6144 rows affected, 1 warning (0.28 sec)

Records: 6144 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 12288 rows affected, 1 warning (0.42 sec)

Records: 12288 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 24576 rows affected, 1 warning (0.99 sec)

Records: 24576 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 49152 rows affected, 1 warning (1.98 sec)

Records: 49152 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 98304 rows affected, 1 warning (4.04 sec)

Records: 98304 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 196608 rows affected, 1 warning (8.89 sec)

Records: 196608 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 393216 rows affected, 1 warning (17.14 sec)

Records: 393216 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 786432 rows affected, 1 warning (38.07 sec)

Records: 786432 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 1572864 rows affected, 1 warning (1 min 11.91 sec)

Records: 1572864 Duplicates: 0 Warnings: 1

mysql> insert into user(username,password) select username,password from user;/

Query OK, 3145728 rows affected, 1 warning (2 min 29.04 sec)

Records: 3145728 Duplicates: 0 Warnings: 1

推荐阅读
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 学习SLAM的女生,很酷
    本文介绍了学习SLAM的女生的故事,她们选择SLAM作为研究方向,面临各种学习挑战,但坚持不懈,最终获得成功。文章鼓励未来想走科研道路的女生勇敢追求自己的梦想,同时提到了一位正在英国攻读硕士学位的女生与SLAM结缘的经历。 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • Ubuntu 9.04中安装谷歌Chromium浏览器及使用体验[图文]
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • Ubuntu安装常用软件详细步骤
    目录1.GoogleChrome浏览器2.搜狗拼音输入法3.Pycharm4.Clion5.其他软件1.GoogleChrome浏览器通过直接下载安装GoogleChro ... [详细]
  • 2016 linux发行版排行_灵越7590 安装 linux (manjarognome)
    RT之前做了一次灵越7590黑苹果炒作业的文章,希望能够分享给更多不想折腾的人。kawauso:教你如何给灵越7590黑苹果抄作业​zhuanlan.z ... [详细]
  • 本文介绍了在Ubuntu 11.10 x64环境下安装Android开发环境的步骤,并提供了解决常见问题的方法。其中包括安装Eclipse的ADT插件、解决缺少GEF插件的问题以及解决无法找到'userdata.img'文件的问题。此外,还提供了相关插件和系统镜像的下载链接。 ... [详细]
  • 像跟踪分布式服务调用那样跟踪Go函数调用链 | Gopher Daily (2020.12.07) ʕ◔ϖ◔ʔ
    每日一谚:“Acacheisjustamemoryleakyouhaven’tmetyet.”—Mr.RogersGo技术专栏“改善Go语⾔编程质量的50个有效实践” ... [详细]
  • 开发笔记:Python之路第一篇:初识Python
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Python之路第一篇:初识Python相关的知识,希望对你有一定的参考价值。Python简介& ... [详细]
  • FIN7后门工具伪装成白帽工具进行传播
    fin7,后门,工具,伪装,成,白, ... [详细]
  • OAuth2.0指南
    引言OAuth2.0是一种应用之间彼此访问数据的开源授权协议。比如,一个游戏应用可以访问Facebook的用户数据,或者一个基于地理的应用可以访问Foursquare的用户数据等。 ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了Flutter添加APP启动StoryView相关的知识,希望对你有一定的参考价值。 ... [详细]
  • MybatisPlus入门系列(13) MybatisPlus之自定义ID生成器
    数据库ID生成策略在数据库表设计时,主键ID是必不可少的字段,如何优雅的设计数据库ID,适应当前业务场景,需要根据需求选取 ... [详细]
  • 这也太简单了!轻松操作Feign 服务调用使用 Zipkin 链路追踪!
    0、介绍分布式微服务时代,方便了业务的快速增长和服务的稳定,但是系统出现问题后,面对同业务多服务排查起来令人头大。这时候领导就想着集成分布式追踪系统。Zipkin是T ... [详细]
  • imx6ull开发板驱动MT7601U无线网卡的方法和步骤详解
    本文详细介绍了在imx6ull开发板上驱动MT7601U无线网卡的方法和步骤。首先介绍了开发环境和硬件平台,然后说明了MT7601U驱动已经集成在linux内核的linux-4.x.x/drivers/net/wireless/mediatek/mt7601u文件中。接着介绍了移植mt7601u驱动的过程,包括编译内核和配置设备驱动。最后,列举了关键词和相关信息供读者参考。 ... [详细]
author-avatar
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有