日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

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

2、
mysql -uroot -pD******** -- 導出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文件,這樣分批導入更快,更方便,參考這里:http://www.nowamagic.net/librarys/veda/detail/2495,但是不能使用按容量啊,一定要按行。說日志太大拿不回來的,罰面壁一小時! 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、優化環境配置,準備開始導入 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、恢復現場 SET autocommit=1; SET unique_checks=1; SET foreign_key_checks=1; set sql_log_bin=1;

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

?補充一下測試結果,但這臺機器實在是太NB了,可能一般的客戶沒有這樣的條件,供參考吧:

?測試表:
?t_resource_info
?記錄個數:1582937


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

二、重新導入
[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??? : 開始執行SQL腳本...
2017-11-05 16:59:27,223 INFO??? : SQL腳本執行成功!
導入需要79秒

合計需要114秒。

===================================================================================================
測試用機:

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

CPU核數:
cat /proc/cpuinfo| grep "cpu cores"


邏輯處理器個數:
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

內存:
cat /proc/meminfo
MemTotal:?????? 65845352 kB

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

附10.10.14.224測試用例

[root@localhost TestLoadFile]# python3 ExportData.py
2017-11-06 07:51:14????? 成功創建工作目錄!
2017-11-06 07:51:14????? 開始導出數據...
2017-11-06 07:53:12????? 成功導出數據!
2017-11-06 07:53:12????? 正在進行分割...
2017-11-06 07:53:27????? 成功進行分割!
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??? : 開始執行SQL腳本...
2017-11-06 08:07:40,093 INFO??? : SQL腳本執行成功!

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

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。