對於mysql加索引,刪除索引,添加列,刪除列,修改列順序的最佳辦法測試

來源:互聯網
上載者:User

標籤:txt   最佳化   out   最好   idea   --   rom   mem   min   

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 -psplit -a 2 -d -l 50000 /usr/local/mysql/t_resource_info.txt /usr/local/huanghai/prefix2-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開發起來,基本無困難。

 

對於mysql加索引,刪除索引,添加列,刪除列,修改列順序的最佳辦法測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.