sql自动审核工具-inception
[inception使用规范及说明文档](http://mysql-inception.github.io/inception-document/usage/)
[代码仓库](https://github.com/mysql-inception/inception)
inception介绍
inception是去哪网团队开发的一个集审核、执行、备份及生成回滚语句于一身的MySQL自动化运维工具,
可以集成进mysql自动化运维平台来实现sql的自动审核。
开发语言:C/C++ ,在mysql源码的基础上改造的
限制
目前只支持通过C/C++接口、Python接口对inception的访问
inception充当的角色
inception对于自动化应用程序(简称rid)来说是服务器,对于数据库server来说是客户端。当通过自动化平台提交语句(DML/DDL)后,
执行过程可以概括为(如果rid是Python程序)
- 开发人员提交待审核的sql到rid
- rid将要访问的数据库的连接串封装到sql语句块的头部,然后调用inception
- inception对sql进行语法和语义的检查以及按照参数文件中指定的审核项进行审核
- 审核通过后执行语句
- 通过解析binlog生成回滚语句保存到参数文件指定的备份库中
流程图如下:
inception安装
可以单独部署到一台主机上,并在此主机上创建备份库
- yum install gcc gcc-c++ cmake bison openssl-devel ncurses-devel MySQL-python –y
cd /usr/local/src- git clone https://github.com/smile-java/inception
- cd inception
- # 调用脚本编译安装;指定新生成的文件到目录debug
- sh inception_build.sh debug
编译报错信息
- 安装inception
- sh inception_build.sh debug
- CMake Error at cmake/bison.cmake: (MESSAGE):
- Bison (GNU parser generator) is required to build MySQL.Please install
- bison.
- -- Configuring incomplete, errors occurred!
- See also "/data0/sql/inception/debug/CMakeFiles/CMakeOutput.log".
- See also "/data0/sql/inception/debug/CMakeFiles/CMakeError.log".
- make: *** No rule to make target `install'. Stop.
是缺少依赖包导致,解决是安装bison包,然后将debug删除重新编译安装即可
启动inception服务
- /data0/sql/inception/debug/sql/Inception --defaults-file=/data0/sql/inception/debug/inc.cnf
注意: 因为Inception支持OSC执行的功能,是通过调用pt-online-schema-change工具来做的,但如果Inception后台启动(&)的话,可能会导致pt-online-schema-change在执行完成之后,长时间不返回,进而导致Inception卡死的问题,这个问题后面会解决,但现阶段请尽量不要使用后台启动的方式,或者可以使用nohup Inception启动命令 &
的方式来启动。
inception参数说明
有关审核时参照的规范相关的参数:http://mysql-inception.github.io/inception-document/variables/
有关inception服务器连接的参数
- port
- socket=/自己目录,请自行修改/inc.socket
有关备份库的参数
inception_remote_backup_host //远程备份库的host
inception_remote_backup_port //远程备份库的port
inception_remote_system_user //远程备份库的一个用户
inception_remote_system_password //上面用户的密码
有关支持OSC相关的参数:http://mysql-inception.github.io/inception-document/osc/
使用案例
调用inception的Python模板
- #!/usr/bin/python
- #-\*-coding: utf-8-\*-
- import MySQLdb
- sql='/*--user=admin;--password=123123;--host=127.0.0.1;--execute=1;--port=3309;*/\
- inception_magic_start;\
- use test;\
- query #语句块\
- inception_magic_commit;'
- try:
- conn=MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='',port=123123)
- cur=conn.cursor()
- ret=cur.execute(sql)
- result=cur.fetchall()
- num_fields = len(cur.description)
- field_names = [i[0] for i in cur.description]
- print field_names
- for row in result:
- print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",
- row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
- cur.close()
- conn.close()
- except MySQLdb.Error,e:
- print "Mysql Error %d: %s" % (e.args[0], e.args[1])
DDL操作
如果要调用OSC执行,需要开启参数inception_osc_bin_dir,次参数是会话级别的,每次在提交DDL时可以选择是否通过OSC执行
- #登录到inception
- mysql -uroot -h127.0.0.1 -p123123
- # 使用OSC执行ddl
- inception set session inception_osc_bin_dir='/usr/local/bin'
query为:create table inctest(id int);
执行结果输出
- ['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
- 1 | CHECKED | 0 | Audit completed | None | use test | 0 | '0_0_0' | None | 0 |
- 2 | CHECKED | 1 | Audit completed | Set engine to innodb for table 'inctest'.
- Set charset to one of 'utf8mb4,utf8' for table 'inctest'.
- Set comments for table 'inctest'.
- Column 'id' in table 'inctest' have no comments.
- Column 'id' in table 'inctest' is not allowed to been nullable.
- Set Default value for column 'id' in table 'inctest'
- Set a primary key for table 'inctest'. | create table inctest(id int) | 0 | '0_0_1' | 127_0_0_1_3309_test | 0 |
- errormessage列显示不符合规范的地方,检查的具体项有
- 表必须要有主键,主键为自增,且自增值为1,初始自增值不能大于1
- 表必须有comment、存储引擎必须执行为innodb、表字符集必须是inception参数中配置的其中一个
- 新增的列必须为非空且指定默认值
按规范更改query为:create table inctest(id int unsigned NOT NULL AUTO_INCREMENT comment "id",primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment="test1";
输出为
- ['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
- 1 | RERUN | 0 | Execute Successfully | None | use test | 0 | '1502183472_6520_0' | None | 0.000 |
- 2 | EXECUTED | 0 | Execute Successfully
- Backup successfully | None | create table inctest(id int unsigned NOT NULL AUTO_INCREMENT comment "id",primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment="test1" | 0 | '1502183472_6520_1' | 127_0_0_1_3309_test | 0.110 |
如果sqlsha1列输出非0,则说明使用到了OSC
问题:execute_time列对应的无值
在备份实例中会生成以mysql服务器IP、端口、库名命名的库,此处为127_0_0_1_3309_test
- 09:19:23[127_0_0_1_3309_test](;)> show tables;
- +------------------------------------+
- | Tables_in_127_0_0_1_3309_test |
- +------------------------------------+
- | $_$inception_backup_information$_$ |
- | inctest |
- +------------------------------------+
- 3 rows in set (0.00 sec)
- 09:19:26[127_0_0_1_3309_test](;)> select * from $_$inception_backup_information$_$;
- +-------------------+-------------------+------------------+------------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------+-----------+--------+-----------+------+---------------------+-------------+
- | opid_time | start_binlog_file | start_binlog_pos | end_binlog_file | end_binlog_pos | sql_statement | host | dbname | tablename | port | time | type |
- +-------------------+-------------------+------------------+------------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------+-----------+--------+-----------+------+---------------------+-------------+
- | 1502183472_6520_1 | | 0 | | 0 | create table inctest(id int unsigned NOT NULL AUTO_INCREMENT comment "id",primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment="test1" | 127.0.0.1 | test | inctest | 3309 | 2017-08-08 17:11:12 | CREATETABLE |
- +-------------------+-------------------+------------------+------------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------+-----------+--------+-----------+------+---------------------+-------------+
- 8 rows in set (0.00 sec)
- 09:19:59[127_0_0_1_3309_test](;)> select * from inctest;
- +----+------------------------------+-------------------+
- | id | rollback_statement | opid_time |
- +----+------------------------------+-------------------+
- | 2 | DROP TABLE `test`.`inctest`; | 1502183472_6520_1 |
- +----+------------------------------+-------------------+
- 2 rows in set (0.00 sec)
表$_$inception_backup_information$_$记录的是inception的操作日志
回滚sql存储在和原操作表同名的表中,opid_time是执行语句的唯一序列号,如果知道执行sql的序列号,想要获得对应的回滚sql,可以执行
- select rollback_statement from 127_0_0_1_3309_test.inctest where opid_time =‘1502183472_6520_1’;
sql自动审核工具-inception的更多相关文章
- SQL审核 Inception 中小团队快速构建SQL自动审核系统
SQL审核与执行,作为DBA日常工作中相当重要的一环,一直以来我们都是通过人工的方式来处理,效率低且质量没办法保证.为了规范操作,提高效率,我们决定引入目前市面上非常流行的SQL自动审核工具Incep ...
- 中小团队快速构建SQL自动审核系统
SQL审核与执行,作为DBA日常工作中相当重要的一环,一直以来我们都是通过人工的方式来处理,效率低且质量没办法保证.为了规范操作,提高效率,我们决定引入目前市面上非常流行的SQL自动审核工具Incep ...
- centos 7 安装sql 审核工具 inception + archer
系统环境: Centos7 + python2.7 + python3 .... 下载 源码地址:https://github.com/mysql-inception/inception Incept ...
- 去哪儿网mysql语法审核工具Inception正式开源
Inception不仅仅是一个自动化审核工具,同时还具备执行SQL,并且生成对影响数据的回滚语句(类似于闪回的功能),这样一条龙便捷服务的工具.
- MYSQL SQL 审核工具 (inception安装步骤)
http://blog.csdn.net/wulantian/article/category/5825391
- MySQL审核工具Inception
http://www.ywnds.com/?p=9423 https://github.com/mysql-inception/inception 一.Inception简介 Inception是集审 ...
- SQL审核工具自荐Owls
关键词: sql审批.sql检测.sql执行.备份 概要 这里主要是向大家推荐一款sql检测.审批工具Owls,用于自动检测.审批sql的执行,还有其他的审批.备份.查询等功能.以提高sql的规范化, ...
- MySQL SQL审核平台 inception+archer2.0(亲测)
docker run -d --privileged -v `pwd`/archer_data:/data -p 9306:3306 --name archer --hostname archer - ...
- sql审核工具调研安装-sqlAdvisor和soar
sql审核工具调研 基于soar的sql审核查询平台: https://github.com/beiketianzhuang/data-platform-soar 1.美团工具sqlAdvisor工 ...
随机推荐
- 《超实用的HTML代码段》阅读笔记1——HTML5自动聚焦
在页面加载完成后自动将输入焦点定位到需要的元素,用户就可以直接在改元素中进行输入而不需要手动选择它. 通过autofocus的属性就可以指定这种自动聚焦的功能,示例代码如下: <form nam ...
- Android 麦克风录音带音量大小动态显示的圆形自定义View
1.所谓无图无真相,先上效果图.我们要实现的就是中间那个录音的按钮,周边会显示一圈音量大小的波形 2.VolumCircleBar继承自View,我们进行了自定义,代码如下 package com.r ...
- IOS拉伸之底盖设置
1.选定拉伸 UIImageView *fieldImage=[[UIImageViewalloc]initWithFrame:CGRectMake(37,48+35,240, 32)]; field ...
- Eclipse下对MAVEN进行junit软件测试
一.Maven project management and build automation tool, more and more developers use it to manage the ...
- 洛谷 P2068 统计和
题目描述 给定一个长度为n(n<=100000),初始值都为0的序列,x(x<=10000)次的修改某些位置上的数字,每次加上一个数,然后提出y (y<=10000)个问题,求每段区 ...
- C++ static关键字
一.面向过程中的static 1.修饰全局变量(静态全局变量) (1)静态全局变量在全局数据区分配内存: (2)未经初始化的静态全局变量会被程序自动初始化为0: (3)静态全局变量在申明它的整个文件是 ...
- 用函数式编程思维解析anagrams函数
//函数式编程思维分析 这个排列函数 const anagrams = str => { if (str.length <= 2) return str.length === 2 ? [s ...
- URAL1561 Winnie the Pooh
题目描述: vjudge 题解: 高消(线性基)模$7$. 可以算是板子了. 具体见代码: #include<cstdio> #include<cstring> #includ ...
- Django_外键查询和反查询
一.ForeignKey @property装饰器的作用是返回一个属性特性,在数据库中也有一些小技巧可以拿来用,比如今天要写的外键查询和反向查询的内容. from django.db import m ...
- python面向对象编程(OOP)
python作为一种解释性语言,其主要的编程方式就是面向对象,而且python的框架django也是主要面向对象的编程. 类(class)和对象(object) 类(class)是用来描述具有相同属性 ...