安裝
sudo yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
sudo yum install percona-toolkit
查看觸發器:
方式一:
use information_schema;
select * from TRIGGERS;
方式二:
use database_name;
show triggers;
刪除觸發器:
drop trigger trigger_name
有觸發器pt-online-schema-change將不工作
會出現如下提示:The table fr
.xaxa
has triggers. This tool needs to create its own triggers, so the table cannot already have triggers.
基本原理:
- 使用用戶密碼登錄
- 然後檢查表的創建語句
show create table table_name
進行臨時表的創建, - 根據l
--alter
參數對臨時表進行結構更改 - 創建觸發器,在更新、刪除、插入的時候對臨時表的修改
- 從舊錶向臨時表中拷貝數據
- 修改舊錶名字, 修改臨時表名字
- 刪除舊錶,刪除觸發器
使用實例:爲表加唯一索引, 添加列, 刪除列
time pt-online-schema-change --user=kratos --password=3vUbY52IJ2fJq7KwWPeItNrz8 --host=127.0.0.1 --port=3306 --alter="add unique index tel_name(tel, name)" D=test,t=tb_user --nocheck-replication-filters --nocheck-unique-key-change --max-lag=5 --check-interval=2 --alter-foreign-keys-method=auto --execute --print
# 添加列 --alter="add column address varchar(50) not null default ''"
# 刪除列 --alter="drop column address"
不同的操作就是改一下--alter
裏面的內容
問題:
主從複製 --max-lag=5 --check-interval=2 (設定延遲) 這裏使用默認也可以
外鍵約束 --alter-foreign-keys-method=auto
磁盤空間(1倍)
–no-drop-old-table 不刪除原來的表
性能:
–critical-load=“Threads_running=200”
特別參數:
–nocheck-unique-key-change
–nocheck-replication-filters
測試過程:
-–dry-run --print
使用:
–execute
權威 文檔
查看主從狀態:
SHOW SLAVE STATUS \G
SHOW status;
擴展:類似工具gh-ost