[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程序)

  1. 开发人员提交待审核的sql到rid
  2. rid将要访问的数据库的连接串封装到sql语句块的头部,然后调用inception
  3. inception对sql进行语法和语义的检查以及按照参数文件中指定的审核项进行审核
  4. 审核通过后执行语句
  5. 通过解析binlog生成回滚语句保存到参数文件指定的备份库中

流程图如下:

inception安装

可以单独部署到一台主机上,并在此主机上创建备份库

  1. yum install gcc gcc-c++ cmake bison openssl-devel ncurses-devel MySQL-python y
    cd /usr/local/src
  2. git clone https://github.com/smile-java/inception
  3. cd inception
  4. # 调用脚本编译安装;指定新生成的文件到目录debug
  5. sh inception_build.sh debug

编译报错信息

  1. 安装inception
  2. sh inception_build.sh debug
  3. CMake Error at cmake/bison.cmake: (MESSAGE):
  4. Bison (GNU parser generator) is required to build MySQL.Please install
  5. bison.
  6.  
  7. -- Configuring incomplete, errors occurred!
  8. See also "/data0/sql/inception/debug/CMakeFiles/CMakeOutput.log".
  9. See also "/data0/sql/inception/debug/CMakeFiles/CMakeError.log".
  10. make: *** No rule to make target `install'. Stop.

是缺少依赖包导致,解决是安装bison包,然后将debug删除重新编译安装即可

启动inception服务

  1. /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模板

  1. #!/usr/bin/python
  2. #-\*-coding: utf-8-\*-
  3. import MySQLdb
  4. sql='/*--user=admin;--password=123123;--host=127.0.0.1;--execute=1;--port=3309;*/\
  5. inception_magic_start;\
  6. use test;\
  7. query #语句块\
  8. inception_magic_commit;'
  9. try:
  10. conn=MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='',port=123123)
  11. cur=conn.cursor()
  12. ret=cur.execute(sql)
  13. result=cur.fetchall()
  14. num_fields = len(cur.description)
  15. field_names = [i[0] for i in cur.description]
  16. print field_names
  17. for row in result:
  18. print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",
  19. row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
  20. cur.close()
  21. conn.close()
  22. except MySQLdb.Error,e:
  23. print "Mysql Error %d: %s" % (e.args[0], e.args[1])

DDL操作

如果要调用OSC执行,需要开启参数inception_osc_bin_dir,次参数是会话级别的,每次在提交DDL时可以选择是否通过OSC执行

  1. #登录到inception
  2. mysql -uroot -h127.0.0.1 -p123123
  3. # 使用OSC执行ddl
  4. inception set session inception_osc_bin_dir='/usr/local/bin'

query为:create table inctest(id int);

执行结果输出

  1. ['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
  2. 1 | CHECKED | 0 | Audit completed | None | use test | 0 | '0_0_0' | None | 0 |
  3. 2 | CHECKED | 1 | Audit completed | Set engine to innodb for table 'inctest'.
  4. Set charset to one of 'utf8mb4,utf8' for table 'inctest'.
  5. Set comments for table 'inctest'.
  6. Column 'id' in table 'inctest' have no comments.
  7. Column 'id' in table 'inctest' is not allowed to been nullable.
  8. Set Default value for column 'id' in table 'inctest'
  9. Set a primary key for table 'inctest'. | create table inctest(id int) | 0 | '0_0_1' | 127_0_0_1_3309_test | 0 |
  1. 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";

输出为

  1. ['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
  2. 1 | RERUN | 0 | Execute Successfully | None | use test | 0 | '1502183472_6520_0' | None | 0.000 |
  3. 2 | EXECUTED | 0 | Execute Successfully
  4. 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

  1. 09:19:23[127_0_0_1_3309_test](;)> show tables;
  2. +------------------------------------+
  3. | Tables_in_127_0_0_1_3309_test |
  4. +------------------------------------+
  5. | $_$inception_backup_information$_$ |
  6. | inctest |
  7. +------------------------------------+
  8. 3 rows in set (0.00 sec)
  9.  
  10. 09:19:26[127_0_0_1_3309_test](;)> select * from $_$inception_backup_information$_$;
  11. +-------------------+-------------------+------------------+------------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------+-----------+--------+-----------+------+---------------------+-------------+
  12. | opid_time | start_binlog_file | start_binlog_pos | end_binlog_file | end_binlog_pos | sql_statement | host | dbname | tablename | port | time | type |
  13. +-------------------+-------------------+------------------+------------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------+-----------+--------+-----------+------+---------------------+-------------+
  14. | 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 |
  15. +-------------------+-------------------+------------------+------------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------+-----------+--------+-----------+------+---------------------+-------------+
  16. 8 rows in set (0.00 sec)
  17.  
  18. 09:19:59[127_0_0_1_3309_test](;)> select * from inctest;
  19. +----+------------------------------+-------------------+
  20. | id | rollback_statement | opid_time |
  21. +----+------------------------------+-------------------+
  22. | 2 | DROP TABLE `test`.`inctest`; | 1502183472_6520_1 |
  23. +----+------------------------------+-------------------+
  24. 2 rows in set (0.00 sec)

表$_$inception_backup_information$_$记录的是inception的操作日志

回滚sql存储在和原操作表同名的表中,opid_time是执行语句的唯一序列号,如果知道执行sql的序列号,想要获得对应的回滚sql,可以执行

  1. select rollback_statement from 127_0_0_1_3309_test.inctest where opid_time =‘1502183472_6520_1’;

sql自动审核工具-inception的更多相关文章

  1. SQL审核 Inception 中小团队快速构建SQL自动审核系统

    SQL审核与执行,作为DBA日常工作中相当重要的一环,一直以来我们都是通过人工的方式来处理,效率低且质量没办法保证.为了规范操作,提高效率,我们决定引入目前市面上非常流行的SQL自动审核工具Incep ...

  2. 中小团队快速构建SQL自动审核系统

    SQL审核与执行,作为DBA日常工作中相当重要的一环,一直以来我们都是通过人工的方式来处理,效率低且质量没办法保证.为了规范操作,提高效率,我们决定引入目前市面上非常流行的SQL自动审核工具Incep ...

  3. centos 7 安装sql 审核工具 inception + archer

    系统环境: Centos7 + python2.7 + python3 .... 下载 源码地址:https://github.com/mysql-inception/inception Incept ...

  4. 去哪儿网mysql语法审核工具Inception正式开源

    Inception不仅仅是一个自动化审核工具,同时还具备执行SQL,并且生成对影响数据的回滚语句(类似于闪回的功能),这样一条龙便捷服务的工具.

  5. MYSQL SQL 审核工具 (inception安装步骤)

    http://blog.csdn.net/wulantian/article/category/5825391

  6. MySQL审核工具Inception

    http://www.ywnds.com/?p=9423 https://github.com/mysql-inception/inception 一.Inception简介 Inception是集审 ...

  7. SQL审核工具自荐Owls

    关键词: sql审批.sql检测.sql执行.备份 概要 这里主要是向大家推荐一款sql检测.审批工具Owls,用于自动检测.审批sql的执行,还有其他的审批.备份.查询等功能.以提高sql的规范化, ...

  8. MySQL SQL审核平台 inception+archer2.0(亲测)

    docker run -d --privileged -v `pwd`/archer_data:/data -p 9306:3306 --name archer --hostname archer - ...

  9. sql审核工具调研安装-sqlAdvisor和soar

    sql审核工具调研  基于soar的sql审核查询平台: https://github.com/beiketianzhuang/data-platform-soar 1.美团工具sqlAdvisor工 ...

随机推荐

  1. 《超实用的HTML代码段》阅读笔记1——HTML5自动聚焦

    在页面加载完成后自动将输入焦点定位到需要的元素,用户就可以直接在改元素中进行输入而不需要手动选择它. 通过autofocus的属性就可以指定这种自动聚焦的功能,示例代码如下: <form nam ...

  2. Android 麦克风录音带音量大小动态显示的圆形自定义View

    1.所谓无图无真相,先上效果图.我们要实现的就是中间那个录音的按钮,周边会显示一圈音量大小的波形 2.VolumCircleBar继承自View,我们进行了自定义,代码如下 package com.r ...

  3. IOS拉伸之底盖设置

    1.选定拉伸 UIImageView *fieldImage=[[UIImageViewalloc]initWithFrame:CGRectMake(37,48+35,240, 32)]; field ...

  4. Eclipse下对MAVEN进行junit软件测试

    一.Maven project management and build automation tool, more and more developers use it to manage the ...

  5. 洛谷 P2068 统计和

    题目描述 给定一个长度为n(n<=100000),初始值都为0的序列,x(x<=10000)次的修改某些位置上的数字,每次加上一个数,然后提出y (y<=10000)个问题,求每段区 ...

  6. C++ static关键字

    一.面向过程中的static 1.修饰全局变量(静态全局变量) (1)静态全局变量在全局数据区分配内存: (2)未经初始化的静态全局变量会被程序自动初始化为0: (3)静态全局变量在申明它的整个文件是 ...

  7. 用函数式编程思维解析anagrams函数

    //函数式编程思维分析 这个排列函数 const anagrams = str => { if (str.length <= 2) return str.length === 2 ? [s ...

  8. URAL1561 Winnie the Pooh

    题目描述: vjudge 题解: 高消(线性基)模$7$. 可以算是板子了. 具体见代码: #include<cstdio> #include<cstring> #includ ...

  9. Django_外键查询和反查询

    一.ForeignKey @property装饰器的作用是返回一个属性特性,在数据库中也有一些小技巧可以拿来用,比如今天要写的外键查询和反向查询的内容. from django.db import m ...

  10. python面向对象编程(OOP)

    python作为一种解释性语言,其主要的编程方式就是面向对象,而且python的框架django也是主要面向对象的编程. 类(class)和对象(object) 类(class)是用来描述具有相同属性 ...