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

MySQL在Web應用中的主要作用是存儲和管理數據。 1.MySQL高效處理用戶信息、產品目錄和交易記錄等數據。 2.通過SQL查詢,開發者能從數據庫提取信息生成動態內容。 3.MySQL基於客戶端-服務器模型工作,確保查詢速度可接受。

構建MySQL數據庫的步驟包括:1.創建數據庫和表,2.插入數據,3.進行查詢。首先,使用CREATEDATABASE和CREATETABLE語句創建數據庫和表,然後用INSERTINTO語句插入數據,最後用SELECT語句查詢數據。

MySQL適合初學者,因為它易用且功能強大。 1.MySQL是關係型數據庫,使用SQL進行CRUD操作。 2.安裝簡單,需配置root用戶密碼。 3.使用INSERT、UPDATE、DELETE、SELECT進行數據操作。 4.複雜查詢可使用ORDERBY、WHERE和JOIN。 5.調試需檢查語法,使用EXPLAIN分析查詢。 6.優化建議包括使用索引、選擇合適數據類型和良好編程習慣。

MySQL適合初學者,因為:1)易於安裝和配置,2)有豐富的學習資源,3)SQL語法直觀,4)工具支持強大。儘管如此,初學者需克服數據庫設計、查詢優化、安全管理和數據備份等挑戰。

是的,sqlisaprogramminglanguges pecialized fordatamanage.1)它具有焦點,focusingonwhattoachieveratherthanhow.2)sqlisessential forquerying forquerying,插入,更新,更新,和detletingdatainrelationalDatabases.3)

ACID屬性包括原子性、一致性、隔離性和持久性,是數據庫設計的基石。 1.原子性確保事務要么完全成功,要么完全失敗。 2.一致性保證數據庫在事務前後保持一致狀態。 3.隔離性確保事務之間互不干擾。 4.持久性確保事務提交後數據永久保存。

MySQL既是數據庫管理系統(DBMS),也與編程語言緊密相關。 1)作為DBMS,MySQL用於存儲、組織和檢索數據,優化索引可提高查詢性能。 2)通過SQL與編程語言結合,嵌入在如Python中,使用ORM工具如SQLAlchemy可簡化操作。 3)性能優化包括索引、查詢、緩存、分庫分錶和事務管理。

MySQL使用SQL命令管理數據。 1.基本命令包括SELECT、INSERT、UPDATE和DELETE。 2.高級用法涉及JOIN、子查詢和聚合函數。 3.常見錯誤有語法、邏輯和性能問題。 4.優化技巧包括使用索引、避免SELECT*和使用LIMIT。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

WebStorm Mac版
好用的JavaScript開發工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中