超贊!墻裂推薦一個MySQL自動化運維工具!
在這之前,民工哥也給大家介紹過一款開源的SQL管理工具:自動補全、回滾!介紹一款可視化 sql 診斷利器。
今天,民工哥再給大家推薦一款SQL審核利器:goinception。
goinception介紹
goInception是一個集審核、執(zhí)行、備份及生成回滾語句于一身的MySQL運維工具, 通過對執(zhí)行SQL的語法解析,返回基于自定義規(guī)則的審核結果,并提供執(zhí)行和備份及生成回滾語句的功能。
github地址:https://github.com/hanchuanchuan/goInception
文檔:https://hanchuanchuan.github.io/goInception/
goinception架構
goinception安裝
官方提供了幾種的安裝方式,如下。
- 1、源碼安裝
源碼安裝需要有go V1.2版本以上的環(huán)境,使用go mod作依賴管理。
- [root@centos7 ~]# git clone https://github.com/hanchuanchuan/goInception.git
- [root@centos7 ~]# cd goInception
- [root@centos7 ~]# make parser
- [root@centos7 ~]# go build -o goInception tidb-server/main.go
- 2、docker方式
- [root@centos7 ~]# docker pull hanchuanchuan/goinception
- 3、二進制安裝(推薦)
直接上官方提供的地址:https://github.com/hanchuanchuan/goInception/releases/download/去下載對應的版本文件,下載完成后直接解壓運行即可。
- [root@centos7 ~]# mkdir goinception
- [root@centos7 ~]# tar zxf goInception-linux-amd64-v1.2.3.tar.gz -C ./goinception/
- [root@centos7 ~]# cd goinception/
- [root@centos7 goinception]# ll
- total 38476
- drwxr-xr-x 2 root root 33 Aug 30 03:48 config
- -rwxr-xr-x 1 501 games 39399424 May 22 07:45 goInception
解壓完成后,在config目錄下會看到一個默認的配置文件:config.toml.default,大家可以根據(jù)實際情況修改。
goInception采用TiDB源碼重構,所以部分參數(shù)可參考TiDB相關文檔
config.toml文件由幾部分組成,分別為最外層配置如host,port等,以及各分組如[inc],[log]等。示例(該示例僅為展示config.toml文件結構,詳細參數(shù)請參考):https://github.com/hanchuanchuan/goInception/blob/master/config/config.toml.default
- host = "0.0.0.0"
- port = 4000
- path = "/tmp/tidb"
- [log]
- # 日志參數(shù)
- level = "info"
- format = "text"
- [log.file]
- # 日志文件參數(shù)
- filename = ""
- max-size = 300
- [inc]
- # 審核選項
- enable_nullable = true
- enable_drop_table = false
- check_table_comment = false
- check_column_comment = false
- # 等等...
- [osc]
- # pt-osc參數(shù)
- osc_on = false
- osc_min_table_size = 16
- [ghost]
- # gh-ost參數(shù)
- ghost_allow_on_master = true
配置修改完成后,就可以正常啟動了。
- [root@centos7 goinception]# ./goInception -config=config/config.toml
- [root@centos7 ~]# netstat -lntp|grep 4000
- tcp6 0 0 :::4000 :::* LISTEN 1250/./goInception
使用實例
- /*--user=root;--password=root;--host=127.0.0.1;--check=1;--port=3306;*/
- inception_magic_start;
- use test;
- create table t1(id int primary key);
- inception_magic_commit;
其它介紹
1、結果信息
給用戶返回的信息有兩種,
- 一種是提交給goInception的基礎信息存在錯誤,比如源信息不全,或者源信息有錯誤等,這種情況下,直接報異常,包括錯誤碼及錯誤信息,與MySQL服務器的異常是一樣的,在外面正常處理即可。
- 二是如果沒有上面的問題,都會以結果集的方式將檢查結果告訴客戶端。和mysql原生結果集一致。返回的結果集中,每一個行數(shù)據(jù),就是一條提交的SQL語句,goInception內部將所有提交的語句塊一條條的拆開,以結果集的方式返回,針對每一條語句,有什么問題或者狀態(tài),在結果集中是一目了然。
注意:如果在語句中出現(xiàn)語法錯誤,則不能繼續(xù)了,因為goInception已經(jīng)不能將剩下的語句分開了,那么此時前面已經(jīng)正常檢查的多行為多個結果集的行返回,后面出錯的語句為一行返回,當然這個的錯誤信息是語法錯誤。
2、自帶備份功能
自帶備份功能,首先服務啟動時配置config.toml(放在 [inc] 段)
參數(shù) | 默認 | 可選范圍 | 說明 |
---|---|---|---|
backup_host | "" | string | 備份數(shù)據(jù)庫IP地址 |
backup_port | 0 | int | 備份數(shù)據(jù)庫端口 |
backup_user | "" | string | 備份數(shù)據(jù)庫用戶名 |
backup_password | "" | string | 備份數(shù)據(jù)庫密碼 |
并且在執(zhí)行sql時,添加 --backup=true 或 --backup=1 選項。
3、審核規(guī)則
相關的審核規(guī)則,審核選項等詳細信息,可以參考:
- https://hanchuanchuan.github.io/goInception/rules.html
對比Inception
1、功能對比
2、速度
3、使用
這類工具在一定程度上解放了DBA的雙手,而且還能在很大程度上避免出錯的情況,從而保證SQL的執(zhí)行正確率,同時還提供SQL回滾功能,在出錯時進行回滾,保證數(shù)據(jù)安全與完整性。