原理就再也不此處介紹了,你們能夠自行度娘html
哪些ddl是不能夠作的,作了容易出錯:mysql
注意事項:
1.若是異常終止pt-online-schema-change程序,新表上的觸發器不會自動刪除,若是要刪除新表,那麼必需要先刪除觸發器,而後再刪除新表,不然向老表插入數據會由於找不到新表而報錯,致使老表寫入數據失敗sql
2.在添加有中文備註的列時記得要指定字符集 --charset=utf8 ;若是沒有指定字符集--charset=utf8 會致使表全部的表結構註釋亂碼 在改完變後查看錶結構註釋亂碼,這個可直接使用客戶端軟件修改回去,修改註釋不影響什麼數據庫
3.若是在誤在從庫上執行了pt-online-schema-change操做,未執行完成不要取消,等到執行完成了,在修改爲原來的狀態。
4.若是在誤在從庫上執行了pt-online-schema-change操做,未執行完成取消的話,刪除有 pt-online-schema-change在從庫上建立的臨時表和觸發器便可併發
必須在master庫上執行下面的命令app
time pt-online-schema-change --user=root --password='lzlzl89723' --port=3306 --host=localhost --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load=threads_connected:500,threads_running:200 --max-load=threads_connected:300,threads_running:150 --max-lag=4 --alter "DROP key index_experienceId" D=appdb,t=hf_ad_experience_detail --print --execute
time pt-online-schema-change --user=root --password='lzlzl89723' --port=3306 --host=localhost --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load=threads_connected:500,threads_running:200 --max-load=threads_connected:300,threads_running:150 --max-lag=4 --alter "ADD INDEX index_experienceId (experienceId)" D=appdb,t=hf_ad_experience_detail --print --execute
[root@localhost ~]# time pt-online-schema-change --user=root --password='lzlzldleler' --port=3306 --host=localhost --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load threads_connected:500,threads_running:200 --max-load threads_connected:300,threads_running:150 --alter "ADD INDEX index_phone(phone)" D=appDB,t=hf_user --print --execute Cannot connect to MySQL: DBI connect('appDB;host=localhost;port=3306;charset=utf8;mysql_read_default_group=client','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at /usr/local/percona-toolkit/bin/pt-online-schema-change line 2345. real 0m0.246s user 0m0.201s sys 0m0.032s
報錯,當主機名爲localhost時,pt-online-schema-change連接數據庫 默認是找socket /var/lib/mysql/mysql.sock 文件來登陸數據庫,
然而本機的mysql的socket文件是/tmp/mysql.sock,致使pt-online-schema-change經過localhost主機名連接數據庫失敗。
因而受權127.0.0.1 做爲登陸mysql的帳戶:socket
grant all on *.* to root@'127.0.0.1' identified by 'lzlzldleler';flush privileges;
成功解決上訴報錯。ide
表hf_user_action 字段 userId, dataType, opeUser 建立聯合索引:
當前此表記錄數爲: 4408200
建立此聯合索引用時:2分18s搞定高併發
time pt-online-schema-change --user=root --password='lzlzldleler‘ --port=3306 --host=127.0.0.1 --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load threads_connected:500,threads_running:200 --max-load threads_connected:300,threads_running:150 --alter "ADD INDEX index_userId_dataType_opeUser(userId,dataType,opeUser)" D=appDB,t=hf_user_action --print --execute
time pt-online-schema-change --user=root --password='lzlzldleler' --port=3306 --host=localhost --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load=threads_connected:500,threads_running:200 --max-load=threads_connected:300,threads_running:150 --max-lag=4 --alter='add column vip int' D=appDB,t=lz_ad_experience_detail --print --execute
time pt-online-schema-change --user=root --password='lzlzldleler' --port=3306 --host=localhost --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load=threads_connected:500,threads_running:200 --max-load=threads_connected:300,threads_running:150 --max-lag=4 --alter='drop column vip int' D=appDB,t=lz_ad_experience_detail --print --execute
time pt-online-schema-change --user=root --password='lzlzldleler' --port=3306 --host=localhost --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load=threads_connected:500,threads_running:200 --max-load=threads_connected:300,threads_running:150 --max-lag=4 --alter='modify column sid bigint(25)' D=appDB,t=lz_ad_experience_detail --print --execute
time pt-online-schema-change --user=pt_tools --password='NITOcsFLV' --port=3306 --host=目標庫IP地址 --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load=threads_connected:500,threads_running:200 --max-load=threads_connected:300,threads_running:150 --max-lag=4 --alter="ADD gray_phone tinyint(4) NOT NULL DEFAULT 0 COMMENT '號碼是否都爲灰色1:是;0:否'" D=db_crm,t=t_customer_ext --print --execute
code
time pt-online-schema-change --user=pt_tools --password='NITsFLV' --port=3306 --host=目標庫IP地址 --charset=utf8 --check-interval=5 --chunk-size=1000 --chunk-size-limit=4 --chunk-time=1 --nocheck-replication-filters --critical-load=threads_connected:500,threads_running:200 --max-load=threads_connected:300,threads_running:150 --max-lag=4 --alter "modify from_order_id varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '原訂單號'" D=db_mall_bill_test01,t=b_bill_allocate --print --execute --no-check-alter
簡單演示到此爲止
參考資料:
https://www.cnblogs.com/allenhu320/p/11358652.html
http://www.javashuo.com/article/p-mbshjkvw-km.html