ä¸ç´æç®å®è£  Inception ï¼ä¹ä¸ç´æå°ç°å¨ï¼çç Inception éæºãæ github ä¸ä¿åäºä¸ä»½ï¼å¹¶ä¸éå½å为  SQLaudit ãè½ç¶éæºäºï¼ä½æ¯è¿æ¯è½ç¨çï¼ç°å¨å®è£ æµè¯ã
Â
çæ¬ä¿¡æ¯ï¼
çæ¬ä¿¡æ¯ï¼
CentOS 7 x86_64
Inception2.1.50 for Linux on x86_64 (Source distribution)
# rpm -qa | grep -E '^(cmake|ncurses|openssl|bison|gcc-c++)'
openssl-devel-1.0.2k-16.el7.x86_64
cmake-2.8.12.2-2.el7.x86_64
ncurses-base-5.9-14.20130511.el7_4.noarch
ncurses-5.9-14.20130511.el7_4.x86_64
bison-3.0.4-2.el7.x86_64
bison-devel-3.0.4-2.el7.x86_64
ncurses-libs-5.9-14.20130511.el7_4.x86_64
gcc-c++-4.8.5-36.el7.x86_64
openssl-libs-1.0.2k-16.el7.x86_64
ncurses-devel-5.9-14.20130511.el7_4.x86_64
openssl-1.0.2k-16.el7.x86_64
å®è£ åï¼MySQL éè¦é 置以ä¸å 个åæ°ï¼ç¨äº inception è®°å½ååæ»ç
# vim /etc/my.cnf
[mysqld]
log-bin=/usr/local/mysql/binlog/mysql-bin
binlog_format = row #mixed/row
server_id = 10
Â
=============================== å¼å§å®è£ ==============================
å®è£ ç¸å ³å
yum install -y cmake ncurses-devel openssl-devel bison-devel gcc-c++ MySQL-python
å®è£ percona-toolkit (éè¦ç¨å° pt-online-schema-change)
wget https://www.percona.com/downloads/percona-toolkit/3.0.12/binary/redhat/7/x86_64/percona-toolkit-3.0.12-1.el7.x86_64.rpm
rpm -ivh percona-toolkit-3.0.12-1.el7.x86_64.rpm
ll /usr/bin/pt-*
ä¸è½½Â SQLauditï¼inception ï¼æºç ï¼å½å为 "inception-master"
wget https://github.com/weiyanwei412/SQLaudit/archive/master.zip
unzip master.zip
mv SQLaudit-master /opt/inception-master
cd /opt/inception-master
ä½æ¯ç¼è¯æç¹é®é¢ãå¨ CentOS ä¸ï¼è¿ 2 ç§ç¼è¯æ¹æ³å¯è½é误
-----------------------------------------------------------
# é误ä¸ï¼
# sh inception_build.sh /usr/local/inception
-----------------------------------------------------------
building project in /usr/local/inception
CMake Error: The source directory "/usr/local" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
make: *** No rule to make target `install. Stop.
-----------------------------------------------------------
# é误äºï¼
# sh inception_build.sh inception [linux]
-----------------------------------------------------------
-- Running cmake version 2.8.12.2
CMake Warning (dev) at CMakeLists.txt:141 (INCLUDE):
Syntax Warning in cmake code at
/opt/inception-master/cmake/ssl.cmake:207:55
Argument not separated from preceding token by whitespace.
This warning is for project developers. Use -Wno-dev to suppress it.
-- MySQL Inception2.1.50
-- Packaging as: mysql-Inception2.1.50-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/inception-master
make: *** No rule to make target `install. Stop.
-----------------------------------------------------------
æ£ç¡®çç¼è¯æ¹æ³
cmake -DWITH_DEBUG=OFF \
-DCMAKE_INSTALL_PREFIX=/usr/local/inception \
-DMYSQL_DATADIR=/usr/local/inception/data \
-DWITH_SSL=yes \
-DCMAKE_BUILD_TYPE=RELEASE \
-DWITH_ZLIB=bundled \
-DMY_MAINTAINER_C_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Wdeclaration-after-statement" \
-DMY_MAINTAINER_CXX_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Wno-unused-parameter -Woverloaded-virtual"
make && make install
Inception é ç½®æ件ï¼/etc/inc.cnfï¼è®¾ç½®
# Inception é
ç½®æ件设置
# vim /etc/inc.cnf
# doc: https://github.com/weiyanwei412/inception-document/blob/master/docs/variables.md
[inception]
port=6669
socket=/usr/local/inception/data/inc.socket
character-set-server=utf8
general_log=1 #å¯ç¨Inceptionè¯å¥æ§è¡è®°å½
general_log_file=/usr/local/inception/data/inception.log
#Inception å®¡æ ¸è§å
inception_check_autoincrement_datatype=1 #建表æ¶ï¼èªå¢åçç±»åä¸ä¸ºintæè
bigint
inception_check_autoincrement_init_value=1 #建表æ¶ï¼èªå¢åçå¼æå®çä¸ä¸º1ï¼åæ¥é
inception_check_autoincrement_name=1 #建表æ¶ï¼å¦ææå®çèªå¢åçååä¸ä¸ºID
inception_check_column_comment=1 #建表æ¶ï¼å没æ注é
inception_check_column_default_value=0 #æ£æ¥å¨å»ºè¡¨ãä¿®æ¹åãæ°å¢åæ¶ï¼åå±æ§æ¯å¦æé»è®¤å¼
inception_check_dml_limit=1 #å¨DMLè¯å¥ä¸ä½¿ç¨äºLIMIT
inception_check_dml_orderby=1 #å¨DMLè¯å¥ä¸ä½¿ç¨äºOrder By
inception_check_dml_where=1 #å¨DMLè¯å¥ä¸æ²¡æWHEREæ¡ä»¶
inception_check_identifier=1 #SQLè¯å¥ååæ£æ¥ï¼å¦æåç°ååä¸åå¨é¤æ°åãåæ¯ãä¸å线ä¹å¤çå符æ¶ï¼ä¼æ¥Identifier "invalidname" is invalid, valid options: [a-z,A-Z,0-9,_].
inception_check_index_prefix=1 #æ¯å¦æ£æ¥ç´¢å¼åååç¼ä¸º"idx_"ï¼æ£æ¥å¯ä¸ç´¢å¼åç¼æ¯ä¸æ¯"uniq_"
inception_check_insert_field=1 #æ¯å¦æ£æ¥æå
¥è¯å¥ä¸çåé¾è¡¨çåå¨æ§
inception_check_primary_key=1 #æ£æ¥æ¯å¦æ主é®
inception_check_table_comment=0 #æ£æ¥è¡¨æ¯å¦æ注é
inception_check_timestamp_default=0 #æ£æ¥è¡¨æ¯å¦ætimestampç±»åæå®é»è®¤å¼
inception_enable_autoincrement_unsigned=1 #æ£æ¥èªå¢åæ¯ä¸æ¯ä¸ºæ 符å·å
inception_enable_blob_type=0 #æ£æ¥æ¯ä¸æ¯æ¯æBLOBå段ï¼å
æ¬å»ºè¡¨ãä¿®æ¹åãæ°å¢åæä½ é»è®¤å¼å¯
inception_enable_column_charset=0 #å
许åèªå·±è®¾ç½®å符é
inception_enable_enum_set_bit=0 #æ¯å¦æ¯æenum,set,bitæ°æ®ç±»å
inception_enable_foreign_key=0 #æ¯å¦æ¯æå¤é®
inception_enable_identifer_keyword=0 #SQLè¯å¥æ¯å¦ææ è¯ç¬¦è¢«åæMySQLçå
³é®å
inception_enable_not_innodb=0 #åå¨å¼ææ¯å¦æå®ä¸ºInnodb
inception_enable_nullable=0 #å建æè
æ°å¢åæ¯å¦å
许为NULL
inception_enable_orderby_rand=0 #æ¯å¦å
许order by rand
inception_enable_partition_table=0 #æ¯å¦æ¯æååºè¡¨
inception_enable_select_star=0 #æ¯å¦å
许 Select*
inception_enable_sql_statistic=1 #å¤åºå®ä¾æ¯å¦åå¨sqlç»è®¡ä¿¡æ¯
inception_max_char_length=16 #å½charç±»åçé¿åº¦å¤§äºè¿ä¸ªå¼æ¶ï¼æ¯å¦æ示转æ¢ä¸ºVARCHAR
inception_max_key_parts=5 #ä¸ä¸ªç´¢å¼ä¸ï¼åçæ大个æ°ï¼è¶
è¿è¿ä¸ªæ°ç®åæ¥é
inception_max_keys=16 #ä¸ä¸ªè¡¨ä¸ï¼æ大çç´¢å¼æ°ç®ï¼è¶
è¿è¿ä¸ªæ°åæ¥é
inception_max_update_rows=10000 #å¨ä¸ä¸ªä¿®æ¹è¯å¥ä¸ï¼é¢è®¡å½±åçæ大è¡æ°ï¼è¶
è¿è¿ä¸ªæ°å°±æ¥é
inception_merge_alter_table=1 #å¨å¤ä¸ªæ¹åä¸ä¸ªè¡¨çè¯å¥åºç°æ¯ï¼æ¯å¦æ示åæä¸ä¸ª
#inception æ¯æ OSC åæ°(pt-online-schema-change)
inception_osc_bin_dir=/usr/bin #ç¨äºæå®pt-online-schema-changeèæ¬çä½ç½®ï¼ä¸å¯ä¿®æ¹ï¼å¨é
ç½®æ件ä¸è®¾ç½®
inception_osc_check_interval=5 #对åºOSCåæ°--check-intervalï¼æä¹æ¯Sleep time between checks for --max-lag.
inception_osc_chunk_size=1000 #对åºOSCåæ°--chunk-size
inception_osc_chunk_size_limit=4 #对åºOSCåæ°--chunk-size-limit
inception_osc_chunk_time=0.1 #对åºOSCåæ°--chunk-time
inception_osc_critical_thread_connected=1000 #对åºåæ°--critical-loadä¸çthread_connectedé¨å
inception_osc_critical_thread_running=80 #对åºåæ°--critical-loadä¸çthread_runningé¨å
inception_osc_drop_new_table=1 #对åºåæ°--[no]drop-new-table
inception_osc_drop_old_table=1 #对åºåæ°--[no]drop-old-table
inception_osc_max_lag=3 #对åºåæ°--max-lag
inception_osc_max_thread_connected=1000 #对åºåæ°--max-loadä¸çthread_connectedé¨å
inception_osc_max_thread_running=80 #对åºåæ°--max-loadä¸çthread_runningé¨å
inception_osc_min_table_size=0 # è¿ä¸ªåæ°å®é
ä¸æ¯ä¸ä¸ªOSCçå¼å
³ï¼å¦æ设置为0ï¼åå
¨é¨ALTERè¯å¥é½èµ°OSCï¼å¦æ设置为é0ï¼åå½è¿ä¸ªè¡¨å ç¨ç©ºé´å¤§å°å¤§äºè¿ä¸ªå¼æ¶æ使ç¨OSCæ¹å¼ãåä½ä¸ºMï¼è¿ä¸ªè¡¨å¤§å°ç计ç®æ¹å¼æ¯éè¿è¯å¥ï¼"select (DATA_LENGTH + INDEX_LENGTH)/1024/1024 from information_schema.tables where table_schema = 'dbname' and table_name = 'tablename'"æ¥å®ç°ç
inception_osc_on=0 #ä¸ä¸ªå
¨å±çOSCå¼å
³ï¼é»è®¤æ¯æå¼çï¼å¦ææ³è¦å
³éå设置为OFFï¼è¿æ ·å°±ä¼ç´æ¥ä¿®æ¹
inception_osc_print_none=1 #ç¨æ¥è®¾ç½®å¨Inceptionè¿åç»æéä¸ï¼å¯¹äºåæ¥OSCå¨æ§è¡è¿ç¨çæ åè¾åºä¿¡æ¯æ¯ä¸æ¯è¦æå°å°ç»æé对åºçé误信æ¯åä¸ï¼å¦æ设置为1ï¼å°±ä¸æå°ï¼å¦æ设置为0ï¼å°±æå°ãèå¦æåºç°é误äºï¼åé½ä¼æå°
inception_osc_print_sql=1 #对åºåæ°--print
#å¤ä»½æå¡å¨ä¿¡æ¯ï¼è®°å½ç¨äºåæ»ï¼éè¦æé CREATEãINSERTï¼åªå¤ä»½æ´æ¹çæ°æ®ï¼
#线ä¸åååºå¯è½å²çªï¼æææ¤å¤åºå½åè§åå¦ï¼IP_Port_dbnameï¼éé¢ç表ä¸å¯¹åºçº¿ä¸è¡¨é½æ¯ä¸ä¸å¯¹åºç
inception_remote_backup_host=10.10.10.10
inception_remote_backup_port=3307
inception_remote_system_user=root
inception_remote_system_password=mysql
inception_support_charset=utf8
å¯å¨åè¿æ¥ Inception
# å¯å¨åè¿æ¥ Inception
nohup /usr/local/inception/bin/Inception --defaults-file=/etc/inc.cnf &
/usr/local/inception/bin/mysql -h10.10.10.10 -P6669
# è¿æ¥åæµè¯æ¥çåé
mysql> inception get variables;
mysql> inception get variables 'connect_timeout';
mysql> inception set connect_timeout=15;
注ï¼å¨æ§è¡æ¶ï¼ä¸è½å° DML è¯å¥å DDL è¯å¥æ¾å¨ä¸èµ·æ§è¡ï¼å¦åä¼å 为å¤ä»½è§£æbinlogæ¶ç±äºè¡¨ç»æçåååºç°ä¸å¯é¢ç¥çé误ï¼å¦æè¦æåæ¶æ§è¡ DML å DDLï¼å请åå¼å¤ä¸ªè¯å¥åå¿æ¥æ§è¡ï¼å¦æççè¿æ ·åäºï¼Inception ä¼æ¥éï¼ä¸ä¼å»æ§è¡
éªè¯SQLèæ¬çåºæ¬è¯æ³
/*--user=root;--password=mysql;--host=10.10.10.10.10;--enable-check;--port=3306;*/ #ç®æ æ°æ®åºè¿æ¥å符串
inception_magic_start; #å¿
é¡»ï¼è¯å¥åå¼å§ï¼å¼å§ç»æé´ä¸ºsqlèæ¬ï¼
use test;
CREATE TABLE inc_table(id int);
inception_magic_commit; #å¿
é¡»ï¼è¯å¥åç»æ
ä½æ¯ï¼ç®ååªæ¯æéè¿C/C++æ¥å£ãPythonæ¥å£æ¥å¯¹Inception访é®ãæ以ç°å¨æµè¯ä½¿ç¨ python èæ¬è¿æ¥ inception å»å®¡æ ¸è¯å¥ãå建 python èæ¬ï¼å 容å¦ä¸ï¼
#!/usr/bin/python
#-*- coding: utf-8 -*-
#Python 2.7.5
import MySQLdb
sql="""/*--user=root;--password=mysql;--host=10.10.10.10;--enable-check;--port=3306;*/
inception_magic_start;
use test;
CREATE TABLE inc_table(id int);
inception_magic_commit;"""
try:
conn=MySQLdb.connect(host='10.10.10.10',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])
è¿åç»æ为ï¼
['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 'inc_table'.
Set charset to one of 'utf8' for table 'inc_table'.
Column 'id' in table 'inc_table' have no comments.
Column 'id' in table 'inc_table' is not allowed to been nullable.
Set a primary key for table 'inc_table'. | CREATE TABLE inc_table(id int) | 0 | '0_0_1' | 10_10_10_10_3306_test | 0 |
Â
æ¥ä¸æ¥ç»§ç»å®è£ WEB 端çå®¡æ ¸å¹³å°Â yearning ãYearning æ¯åºäºInceptionçwebå¯è§åSQLå®¡æ ¸å¹³å°,å ¶æ¬èº«åªæä¾å¯è§å交äºé¡µé¢å¹¶ä¸å ·å¤sqlå®¡æ ¸çè½åãæä»¥å¿ é¡»æé Inceptionä¸èµ·ä½¿ç¨ã建议使ç¨è å çæInception使ç¨æ¹æ³ååè¿è¡ä½¿ç¨ï¼
æ¥ä¸æ¥Yearning é¨ç½²åèï¼ MySQL å®¡æ ¸å¹³å° Yearning é¨ç½²
Â