一 安裝
git clone https://github.com/hanchuanchuan/goInception.git cd goInception make parser go build -o goInception tidb-server/main.go ./goInception -config=config/config.toml
二 配置文件
1 goInception利用的toml模塊作為配置文件
2 配置文件分為幾個模塊
1 inc-審核規則
enable_drop_table = false 禁止drop/truncate_table操作,天然過濾危險
enable_set_engine = true 檢測非innodb引擎
enable_change_column = true 檢測更改列
check_column_type_change = true
index_prefix = "idx_" 索引相關
uniq_index_prefix = "uniq_"
table_prefix = "
# 可選值: "first", "max"
# "first": 使用第一行的explain結果作為受影響行數
# "max": 使用explain結果中的最大值作為受影響行數
explain_rule = "first"
# 安全更新是否開啟(mysql自身的功能).
sql_safe_updates = -1
support_charset = "utf8,utf8mb4"
support_engine = "innodb"
lang = "en-US"
general_log = true
3 具體gh-ost配置(具體問題具體分析)
ghost_aliyun_rds =true 根據環境確定是否開啟阿里雲選項
ghost_on = true
ghost_allow_on_master = true
ghost_assume_rbr = true
ghost_concurrent_rowcount = false
ghost_ok_to_drop_table = false
ghost_initially_drop_ghost_table=true
ghost_initially_drop_old_table=true
ghost_initially_drop_socket_file=true
osc_critical_thread_connected=3000
osc_max_thread_connected=3000
osc_min_table_size=10
三 對比原生inception的優勢
1 對開源工具gh-ost的支持,可以不再使用觸發器
2 支持DML和DDL混合提交
3 批量備份速度遠遠超過原生inception
4 因為是go程序,所以不依賴於環境,執行執行即可,原生inception有一些包的問題
5 支持某些原生incetpion不支持的語法,比如insert select這種帶select關鍵字
6 針對gh-ost的行為是封裝在內部的,外部無法觀測到(我這里發現是這樣的)
7 支持天然過濾drop truncate操作,防止有危險,以前只能從前端和后端程序代碼實現約束
四 用戶權限細化
insert,delete,update,insert,select,create,drop,alter,replication slave,replication client,process,super
五 獲取DDL進度
inception get osc processlist;
inception get osc_percent '*4A673E07E512727FD5858C8CD6E2815FED99F808';
六 官方文檔
https://hanchuanchuan.github.io/goInception/permission.html
七 使用注意
1 構建選項 --backup=1 --execute=1 --check=1
2 如果存在多個ddl sql 會先檢測所有的SQL語句是否能執行,然后才會執行所有語句,如果審核失敗,則返回錯誤信息
3 inception kill/pause/resume osc 'id‘ 管理相關的DDL語句 如果kill 記得清理相關表
CHECKING | 在當前語句 審核完成 后中止審核,此時僅返回從開始到當前語句的審核結果,后續SQL不再審核 |
EXECUTING | 在當前語句 執行完成 后中止執行,如果開啟了備份,會執行備份操作,未開啟則直接返回 |
BACKUP | 在當前binlog事件 解析完成后中止備份,但已生成的回滾語句會繼續寫入備份庫,待寫入完成后返回 |