在此之前,米工哥还介绍了一个开源的SQL管理工具:自动补全和回滚!介绍一个可视化的sql诊断工具。今天米工给大家推荐一个强大的SQL审计工具:goinception。goinception简介goInception是一款集审计、执行、备份、回滚语句生成为一体的MySQL运维工具。通过解析执行SQL的语法,根据自定义规则返回审计结果,并提供执行、备份、回滚生成。语句的作用。github地址:https://github.com/hanchuanchuan/goInception文档:https://hanchuanchuan.github.io/goInception/goinception架构安装goinception官方提供了几种安装方式,如下。1.源码安装源码安装需要goV1.2以上环境,使用gomod进行依赖管理。[root@centos7~]#gitclonehttps://github.com/hanchuanchuan/goInception.git[root@centos7~]#cdgoInception[root@centos7~]#makeparser[root@centos7~]#gobuild-ogoInceptiontidb-server/main.go2.docker方法[root@centos7~]#dockerpullhanchuanchuan/goinception3.二进制安装(推荐)直接到官方地址:https://github.com/hanchuanchuan/goInception/releases/download/下载对应版本文件,下载完成后直接解压运行即可。[root@centos7~]#mkdirgoinception[root@centos7~]#tarzxfgoInception-linux-amd64-v1.2.3.tar.gz-C./goinception/[root@centos7~]#cdgoinception/[root@centos7goinception]#lltotal38476drwxr-xr-x2rootroot33Aug3003:48config-rwxr-xr-x1501games39399424May2207:45goInception解压后会在config目录下看到一个默认的配置文件:config.toml.default,可以根据实际情况修改。goInception使用TiDB源码重构,部分参数可参考TiDB相关文档。config.toml文件由几部分组成,分别是host、port等最外层的配置,以及[inc]、[log]等各组的example(本例只是展示结构config.toml文件,详细参数请参考:https://github.com/hanchuanchuan/goInception/blob/master/config/config.toml.defaulthost="0.0.0.0"port=4000path="/tmp/tidb[log]#日志参数level="info"format="text"[log.file]#日志文件参数filename=""max-size=300[inc]#审计选项enable_nullable=trueenable_drop_table=falsecheck_table_comment=falsecheck_column_comment=false#Wait...[osc]#pt-osc参数osc_on=falseosc_min_table_size=16[ghost]#gh-ost参数ghost_allow_on_master=true配置修改完成后可以正常启动。[root@centos7goinception]#./goInception-config=config/config.toml[root@centos7~]#netstat-lntp|grep4000tcp600:::4000:::*LISTEN1250/./goInception用例/*--user=root;--password=root;--host=127.0.0.1;--check=1;--port=3306;*/inception_magic_start;usetest;createtablet1(idintprimarykey);inception_magic_commit;其他介绍1.返回结果信息到用户有两类信息。一是提交给goInception的基础信息有错误,比如源信息不全或者源信息有误。异常也是一样的,在外面可以正常处理。二是如果没有以上问题,检测结果会以结果集的形式告知客户。与mysql原生结果集一致。在返回的结果集中,每一行数据都是一条提交的SQL语句。GoInception将所有提交的语句块一个一个地拆解,并以结果集的形式返回。对于每条语句,如果有什么问题或者状态,在结果集中一目了然。注意:如果语句有语法错误,则不能继续,因为goInception已经不能再把剩下的语句分开了,那么这时候,之前检查正常的行会作为多个结果集的行返回,而以下语句错误的是返回一行,当然这个错误信息是一个语法错误。2.自包含备份功能自包含备份功能,服务启动时先配置config.toml(放在[inc]段)parameterdefault可选范围descriptionbackup_host""string备份数据库IP地址backup_port0int备份数据库portbackup_user""string备份数据库用户名backup_password""string备份数据库密码,执行sql时,加上--backup=true或--backup=1选项。3.关于审计规则和审计选项的详细信息可以参考:https://hanchuanchuan.github.io/goInception/rules.htmlInception1的比较,功能比较2,speed3,使用这样的工具一定程度上解放了DBA的手,并且可以在很大程度上避免错误,从而保证SQL执行的正确率。同时还提供了SQL回滚功能,在出现错误时回滚,保证数据的安全性和完整性。
