天天看點

extended-insert對mysqldump及導入性能的影響

參數說明:

-e, --extended-insert,長INSERT,多row在一起批量INSERT,提高導入效率,和沒有開啟 -e 的備份導入耗時至少相差3、4倍,預設開啟;用--extended-insert=false關閉。強烈建議開啟,通過下面的測試比較就會明白為什麼了。

一、預設方式導出,也即--extended-insert=true

[root@localhost ~]# time mysqldump -S /tmp/mysql3307.sock -uroot -p'Zhkj@554996' --single-transaction --extended-insert=true -B -A >testdump.sql

Warning: Using a password on the command line interface can be insecure.

real    0m12.965s

user    0m6.579s

sys    0m1.080s

[root@localhost ~]# 

[root@localhost ~]# time mysqldump -S /tmp/mysql3307.sock -uroot -p'Zhkj@554996' --single-transaction  -B -A >1testdump.sql

real    0m13.385s

user    0m6.545s

sys    0m1.171s

二、采用參數--extended-insert=false導出全庫:

[root@localhost ~]# time mysqldump -S /tmp/mysql3307.sock -uroot -p'Zykj@554996' --single-transaction --extended-insert=false -B -A >2testdump.sql

real    0m16.216s

user    0m8.820s

sys    0m1.282s

三、對比到處的sql檔案的大小不一樣:

[root@localhost ~]# du -sh testdump.sql  1testdump.sql 2testdump.sql 

414M    testdump.sql

414M    1testdump.sql

550M    2testdump.sql

四、對比恢複到資料庫所用的時間:

[root@localhost ~]# time mysql -uroot -p -S /tmp/mysql3307.sock < testdump.sql 

Enter password: 

real    3m34.245s

user    0m9.018s

sys    0m0.361s

[root@localhost ~]# time mysql -uroot -p -S /tmp/mysql3307.sock < 2testdump.sql 

real    46m51.702s

user    0m44.712s

sys    0m35.717s

經過上面的一比較,發現導入速度相差非常多。

但是使用--extended-insert=false導出表也有好處

比如資料庫中表中已經存在大量資料,那麼再往表中導入資料時,如果出現主鍵資料沖突Duplicate key error,将會導緻導入操作失敗,但此時如果是使用--extended-insert=false導出表,導入時主鍵沖突的會報錯Duplicate key error,但不沖突的資料仍然能正常導入。

 本文轉自 wjw555 51CTO部落格,原文連結:http://blog.51cto.com/wujianwei/1959493