文档地址:
Docker
利用 Dockerfile 定制Inception镜像使用centos作为基础镜像
Dockerfile:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23FROM docker.io/centos
RUN yum -y install wget git gcc gcc-c++ make cmake openssl-devel ncurses-devel m4
&& cd /opt
&& git clone https://github.com/hhyo/inception.git
&& rpm -i /opt/inception/dockersrc/bison-2.7-4.el7.x86_64.rpm
&& mv /opt/inception/dockersrc/inc.cnf /etc
&& cd inception
&& ./inception_build.sh debug
&& yum -y install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
&& yum -y install percona-toolkit
#修改中文支持
&& rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
&& yum -y install kde-l10n-Chinese && yum -y reinstall glibc-common
&& localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL zh_CN.utf8 #设置环境变量
#port
EXPOSE 6669
#start service
ENTRYPOINT nohup /opt/inception/debug/mysql/bin/Inception --defaults-file=/etc/inc.cnf && bash配置文件inc.cnf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23[inception]
general_log=1
general_log_file=inception.log
port=6669
socket=/tmp/inc.socket
character-set-client-handshake=0
character-set-server=utf8
inception_language_code=zh-CN
inception_remote_system_password=root
inception_remote_system_user=root
inception_remote_backup_port=3306
inception_remote_backup_host=127.0.0.1
inception_support_charset=utf8,utf8mb4
inception_enable_nullable=0
inception_check_primary_key=1
inception_check_column_comment=1
inception_check_table_comment=1
inception_osc_on=OFF
inception_osc_bin_dir=/usr/bin
inception_osc_min_table_size=1
inception_osc_chunk_time=0.1
inception_enable_blob_type=1
inception_check_column_default_value=1构建1docker build -t inception .启动1docker run --name inception -p 6669:6669 -d inception通过MySQL客户端镜进行连接1$ mysql -h127.0.0.1 -P6669查看变量1mysql> inception get variables;
Inception使用
基本的测试脚本,验证Inception工作是否正常1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#!/usr/bin/python
#-*-coding: utf-8-*-
import MySQLdb
sql="/*--user=;--password=;--host=;--check=1;--port=;*/
inception_magic_start;
use mysql;
CREATE TABLE adaptive_office(id int);
inception_magic_commit;"
try:
conn=MySQLdb.connect(host='127.0.0.1',user='',passwd='',db='',port=6669)
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])
web平台archery
archery是一个基于inception的自动化SQL操作平台,支持工单、审核、认证、邮件、OSC等功能。
项目地址:https://github.com/hhyo/archery
实际使用中遇到的问题
日期不支持格式为全0
为了前后端处理方便,业务上面会要求使用全0作为日期的默认值,但是在Inception审核时会报错1
2
3
4
5CREATE TABLE `test_date` (
`id` bigint(20) NOT NULL DEFAULT 0 COMMENT 'id',
`create_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Inception时间格式审核测试'Invalid default value for column ‘create_time’1
2
3
4
5
6
7
8
9
10str_to_time(system_charset_info, res->ptr(), res->length(), <ime, 0, &status);
else
str_to_datetime(system_charset_info, res->ptr(), res->length(), <ime,
- MODE_NO_ZERO_DATE|MODE_NO_ZERO_IN_DATE, &status);
+// MODE_NO_ZERO_DATE|MODE_NO_ZERO_IN_DATE, &status);
+ //允许日期为全0
+ NULL, &status);
//在上面没有检查出来的情况下,还需要对范围溢出做检查
if (status.warnings == 0)
{
TEXT/BLOB类型的列不支持NOT NULL
配置inception_check_column_default_value=1&inception_enable_nullable=0时,创建TEXT/BLOB类型的列并且指定为NOT NULL,审核报错提示cant be not null
审核语句1
2
3
4
5CREATE TABLE `test_text` (
`id` bigint(20) NOT NULL DEFAULT 0 COMMENT 'id',
`ramark text NOT NULL COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Inception审核测试'
执行结果TEXT/BLOB Column ‘ramark’ in table ‘test_text’ can’t been not null.
解决方案修改sql/sql_parse.cc文件
将field->flags & NOT_NULL_FLAG取反1
2
3
4
5if (!(field->flags & NOT_NULL_FLAG) && mysql_field_is_blob(field->sql_type))
{
my_error(ER_TEXT_NOT_NULLABLE_ERROR, MYF(0), field->field_name, table_name);
mysql_errmsg_append(thd);
}新增case ER_TEXT_NIT_NUALLABLE_ERROR1
2case ER_TEXT_NOT_NULLABLE_ERROR:
case ER_NOT_ALLOWED_NULLABLE:
备份语句长度超过限制
解决方案,修改sql/sql_parse.cc文件,text–>longtext1create_sql->append("sql_statement text,");
变更字段类型时的默认值问题
原字段1`media_no` bigint(20) NOT NULL DEFAULT '0' COMMENT '字段验证'
变更语句1
2ALTER TABLE `inception_text`
MODIFY COLUMN `media_no` varchar(20) NOT NULL DEFAULT '' COMMENT '字段验证';
inception审核结果Invalid default value for column ‘media_no’.
参考