日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

对于mysql加索引,删除索引,添加列,删除列,修改列顺序的最佳办法测试

發(fā)布時(shí)間:2023/12/31 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 对于mysql加索引,删除索引,添加列,删除列,修改列顺序的最佳办法测试 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、首先進(jìn)行數(shù)據(jù)訓(xùn)的XltraBackup備份,有備無患,切記切記!

2、
mysql -uroot -pD******** -- 導(dǎo)出csv文件 use dsideal_db;MariaDB [dsideal_db]> SELECT * from t_resource_info INTO OUTFILE "/usr/local/mysql/t_resource_info.txt" FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; Query OK, 1582463 rows affected (29.97 sec)3、切分csv文件,這樣分批導(dǎo)入更快,更方便,參考這里:http://www.nowamagic.net/librarys/veda/detail/2495,但是不能使用按容量啊,一定要按行。說日志太大拿不回來的,罰面壁一小時(shí)! mkdir /usr/local/huanghai -p split -a 2 -d -l 50000 /usr/local/mysql/t_resource_info.txt /usr/local/huanghai/prefix 2-3秒吧3、清空原表,修改字段,反正有備份,不怕的
  truncate t_resource_info;
  
alter table t_resource_info add huanghai_test int;
4、優(yōu)化環(huán)境配置,準(zhǔn)備開始導(dǎo)入 SET autocommit
=0; SET unique_checks=0; SET foreign_key_checks=0; set sql_log_bin=0;SET @innodb_additional_mem_pool_size=26214400; set @innodb_buffer_pool_size=1073741824; set @innodb_log_buffer_size=8388608; set @innodb_log_file_size=268435456;load data infile '/usr/local/huanghai/prefix00' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix01' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix02' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix03' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix04' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix05' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix06' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix07' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix08' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix09' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix10' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix11' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix12' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix13' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix14' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix15' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix16' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix17' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix18' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"'; load data infile '/usr/local/huanghai/prefix19' IGNORE into table dsideal_db.t_resource_info_huanghai fields terminated by ',' enclosed by '"';commit;5、恢復(fù)現(xiàn)場 SET autocommit=1; SET unique_checks=1; SET foreign_key_checks=1; set sql_log_bin=1;

6、建議使用python3進(jìn)行開發(fā)一個(gè)程序,這樣方便串連起來,這是我目前能想到的最好辦法,基本無風(fēng)險(xiǎn),速度上基本能利用磁盤的最大IO,不建議采用修改frm等暴力辦法,那個(gè)對于最后面追加字段的可能還行,對于字段在中間的
可能就是災(zāi)難,而且沒有辦法程序化,這個(gè)辦法是用python3開發(fā)起來,基本無困難。

?補(bǔ)充一下測試結(jié)果,但這臺機(jī)器實(shí)在是太NB了,可能一般的客戶沒有這樣的條件,供參考吧:

?測試表:
?t_resource_info
?記錄個(gè)數(shù):1582937


?一、生成
[root@localhost TestLoadFile]# python3 ExportData.py
2017-11-05 17:03:57????? 成功創(chuàng)建工作目錄!
2017-11-05 17:03:59????? 開始導(dǎo)出數(shù)據(jù)...
2017-11-05 17:04:29????? 成功導(dǎo)出數(shù)據(jù)!
2017-11-05 17:04:29????? 正在進(jìn)行分割...
2017-11-05 17:04:32????? 成功進(jìn)行分割!
導(dǎo)出需要35秒

二、重新導(dǎo)入
[root@localhost TestLoadFile]# python3 ImportData.py
2017-11-05 16:58:08,378 INFO??? : 開始生成SQL腳本...
2017-11-05 16:58:08,380 INFO??? : 成功生成SQL腳本!
2017-11-05 16:58:08,380 INFO??? : 開始執(zhí)行SQL腳本...
2017-11-05 16:59:27,223 INFO??? : SQL腳本執(zhí)行成功!
導(dǎo)入需要79秒

合計(jì)需要114秒。

===================================================================================================
測試用機(jī):

物理機(jī),4顆CPU
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
4

CPU核數(shù):
cat /proc/cpuinfo| grep "cpu cores"


邏輯處理器個(gè)數(shù):
cat /proc/cpuinfo| grep "processor"| wc -l
64

cpu 型號:
[root@localhost TestLoadFile]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
64? Intel(R) Xeon(R) CPU E7-4809 v4 @ 2.10GHz

內(nèi)存:
cat /proc/meminfo
MemTotal:?????? 65845352 kB

===================================================================================================

附10.10.14.224測試用例

[root@localhost TestLoadFile]# python3 ExportData.py
2017-11-06 07:51:14????? 成功創(chuàng)建工作目錄!
2017-11-06 07:51:14????? 開始導(dǎo)出數(shù)據(jù)...
2017-11-06 07:53:12????? 成功導(dǎo)出數(shù)據(jù)!
2017-11-06 07:53:12????? 正在進(jìn)行分割...
2017-11-06 07:53:27????? 成功進(jìn)行分割!
You have new mail in /var/spool/mail/root
[root@localhost TestLoadFile]# python3? ImportData.py
2017-11-06 07:55:37,622 INFO??? : 開始生成SQL腳本...
2017-11-06 07:55:37,629 INFO??? : 成功生成SQL腳本!
2017-11-06 07:55:37,630 INFO??? : 開始執(zhí)行SQL腳本...
2017-11-06 08:07:40,093 INFO??? : SQL腳本執(zhí)行成功!

===================================================================================================

附:測試用例 鏈接:http://pan.baidu.com/s/1dFbCEIl 密碼:75j5

總結(jié)

以上是生活随笔為你收集整理的对于mysql加索引,删除索引,添加列,删除列,修改列顺序的最佳办法测试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。