MySQL Inception安裝使用
Inception 是一個集稽核、執行、備份及生成回滾語句於一身的MySQL自動化運維工具,支援MySQL 5.5、5.6以及Percona等主流版本。
測試環境:CentOS 6.9
下載原始碼
[root@MySQL01 ~]# cd /fire/
[root@MySQL01 fire]# mkdir inception
[root@MySQL01 fire]# cd inception/
[root@MySQL01 inception]# git clone
Initialized empty Git repository in /fire/inception/inception/.git/
remote: Counting objects: 2018, done.
remote: Total 2018 (delta 0), reused 0 (delta 0), pack-reused 2018
Receiving objects: 100% (2018/2018), 11.80 MiB | 37 KiB/s, done.
Resolving deltas: 100% (522/522), done.
安裝依賴包
yum install bison
yum install cmake
yum install ncurses-devel
yum install openssl-devel
yum install gcc-c++ libgcc gcc
透過sh inception_build.sh debug指令碼方式安裝
[root@MySQL01 inception]# sh inception_build.sh debug
...
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql_fix_extensions.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysqltest.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql_client_test.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql_waitpid.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql.server.1
-- Installing: /fire/inception/inception/debug/mysql/man/man8/mysqld.8
-- Installing: /fire/inception/inception/debug/mysql/support-files/solaris/postinstall-solaris
預設會安裝在/fire/inception/inception/debug/mysql下面
編輯配置檔案
啟動
# /fire/inception/inception/debug/mysql/bin/Inception --defaults-file=/etc/inc.cnf &
執行SQL
編輯python 2指令碼,為一張100萬行的大表新增欄位
執行指令碼
[root@MySQL01 script]# python2.6 inception.py
登入Inception檢視OSC的執行過程
語句執行完成
[root@MySQL01 script]# python2.6 inception.py
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | 2 | EXECUTED | 0 | Execute Successfully
Backup successfully | None |
備份及回滾語句的生成條件:
線上伺服器必須要開啟 binlog,在啟動時需要設定引數log_bin、log_bin_index等關於 binlog 的引數。不然不會備份及生成回滾語句。
引數binlog_format必須要設定為 mixed 或者 row 模式。
引數 server_id 必須要設定為非0及非1。
檢視備份表
測試環境:CentOS 6.9
下載原始碼
[root@MySQL01 ~]# cd /fire/
[root@MySQL01 fire]# mkdir inception
[root@MySQL01 fire]# cd inception/
[root@MySQL01 inception]# git clone
Initialized empty Git repository in /fire/inception/inception/.git/
remote: Counting objects: 2018, done.
remote: Total 2018 (delta 0), reused 0 (delta 0), pack-reused 2018
Receiving objects: 100% (2018/2018), 11.80 MiB | 37 KiB/s, done.
Resolving deltas: 100% (522/522), done.
安裝依賴包
yum install bison
yum install cmake
yum install ncurses-devel
yum install openssl-devel
yum install gcc-c++ libgcc gcc
透過sh inception_build.sh debug指令碼方式安裝
[root@MySQL01 inception]# sh inception_build.sh debug
...
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql_fix_extensions.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysqltest.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql_client_test.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql_waitpid.1
-- Installing: /fire/inception/inception/debug/mysql/man/man1/mysql.server.1
-- Installing: /fire/inception/inception/debug/mysql/man/man8/mysqld.8
-- Installing: /fire/inception/inception/debug/mysql/support-files/solaris/postinstall-solaris
預設會安裝在/fire/inception/inception/debug/mysql下面
編輯配置檔案
-
[root@MySQL01 script]# vim /etc/inc.cnf
-
[inception]
-
general_log=1
-
general_log_file=/var/inception/log/inception.log
-
port=6690
-
socket=/fire/inception/inception/debug/mysql/inc.socket
-
character-set-client-handshake=0
-
character-set-server=utf8
-
-
# MySQL支援字符集
-
inception_support_charset=utf8
-
-
inception_remote_backup_host=192.168.56.102
-
inception_remote_backup_port=3306
-
inception_remote_system_user=inception
-
inception_remote_system_password=inception
-
-
#inception_remote_charset=utf8mb4
-
inception_enable_nullable=0
-
inception_check_primary_key=1
-
inception_check_column_comment=1
-
inception_check_table_comment=1
-
inception_enable_blob_type=1
-
inception_check_column_default_value=1
-
-
# OSC
-
inception_osc_on=1
-
inception_osc_min_table_size=1
-
inception_osc_bin_dir=/script/percona-toolkit-3.0.2/bin
-
inception_osc_check_interval=5
- inception_osc_chunk_time=0.1
啟動
# /fire/inception/inception/debug/mysql/bin/Inception --defaults-file=/etc/inc.cnf &
執行SQL
編輯python 2指令碼,為一張100萬行的大表新增欄位
-
[root@MySQL01 script]# vim inception.py
-
#!/usr/bin/python2.6
-
#-\*-coding: utf-8-\*-
-
import MySQLdb
-
sql='/*--user=neo;--password=neo;--host=192.168.56.101;--execute=1;--port=3306;*/\
-
inception_magic_start;\
-
use test;\
-
alter table item_order add loc5 varchar(30) not null default \'xxx\' comment \'efg\';\
-
inception_magic_commit;'
-
try:
-
conn=MySQLdb.connect(host='127.0.0.1',user='',passwd='',db='',port=6690)
-
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])
執行指令碼
[root@MySQL01 script]# python2.6 inception.py
登入Inception檢視OSC的執行過程
-
# /mysql_software_56/bin/mysql -uroot -h 127.0.0.1 -P 6690
-
mysql> inception get osc processlist\G
-
*************************** 1. row ***************************
-
DBNAME: test
-
TABLENAME: item_order
-
COMMAND: alter table item_order add loc5 varchar(30) not null default 'xxx' comment 'efg'
-
SQLSHA1: *862B1979B3751217FE56799A0216A2629F2FFD4C
-
PERCENT: 100
-
REMAINTIME: 00:00
-
INFOMATION: No slaves found. See --recursion-method if host MySQL01 has slaves.
-
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
-
Operation, tries, wait:
-
analyze_table, 10, 1
-
copy_rows, 10, 0.25
-
create_triggers, 10, 1
-
drop_triggers, 10, 1
-
swap_tables, 10, 1
-
update_foreign_keys, 10, 1
-
Not updating foreign keys because --alter-foreign-keys-method=none. Foreign keys that reference the table will no longer work.
-
Altering `test`.`item_order`...
-
Creating new table...
-
CREATE TABLE `test`.`_item_order_new` (
-
`order_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '訂單編號',
-
`loc_id` tinyint(3) unsigned NOT NULL COMMENT '地區編號',
-
`order_create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '訂單生成日期',
-
`order_expire_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '訂單過期日期',
-
`item_id` int(10) unsigned NOT NULL COMMENT '商品編號',
-
`item_cnt` int(10) unsigned NOT NULL COMMENT '商品數量',
-
`order_status` tinyint(3) unsigned NOT NULL COMMENT '訂單狀態,0-失效,1-交易成功',
-
`tran_amount` bigint(20) unsigned NOT NULL COMMENT '交易金額',
-
PRIMARY KEY (`order_id`),
-
KEY `idx_order_loc_status` (`loc_id`,`order_status`,`order_expire_date`),
-
KEY `idx_order_loc_exp` (`loc_id`,`order_expire_date`),
-
KEY `idx_order_stat_loc_item` (`order_status`,`loc_id`,`item_id`,`tran_amount`),
-
KEY `idx_item_id` (`item_id`)
-
) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8 COMMENT='訂單表'
-
Created new table test._item_order_new OK.
-
Altering new table...
-
ALTER TABLE `test`.`_item_order_new` add loc5 varchar(30) not null default 'xxx' comment 'efg'
-
Altered `test`.`_item_order_new` OK.
-
2018-04-07T02:03:33 Creating triggers...
-
CREATE TRIGGER `pt_osc_test_item_order_del` AFTER DELETE ON `test`.`item_order` FOR EACH ROW DELETE IGNORE FROM `test`.`_item_order_new` WHERE `test`.`_item_order_new`.`order_id` <=> OLD.`order_id`
-
CREATE TRIGGER `pt_osc_test_item_order_upd` AFTER UPDATE ON `test`.`item_order` FOR EACH ROW BEGIN DELETE IGNORE FROM `test`.`_item_order_new` WHERE !(OLD.`order_id` <=> NEW.`order_id`) AND `test`.`_item_order_new`.`order_id` <=> OLD.`order_id`;REPLACE INTO `test`.`_item_order_new` (`order_id`, `loc_id`, `order_create_date`, `order_expire_date`, `item_id`, `item_cnt`, `order_status`, `tran_amount`) VALUES (NEW.`order_id`, NEW.`loc_id`, NEW.`order_create_date`, NEW.`order_expire_date`, NEW.`item_id`, NEW.`item_cnt`, NEW.`order_status`, NEW.`tran_amount`);END
-
CREATE TRIGGER `pt_osc_test_item_order_ins` AFTER INSERT ON `test`.`item_order` FOR EACH ROW REPLACE INTO `test`.`_item_order_new` (`order_id`, `loc_id`, `order_create_date`, `order_expire_date`, `item_id`, `item_cnt`, `order_status`, `tran_amount`) VALUES (NEW.`order_id`, NEW.`loc_id`, NEW.`order_create_date`, NEW.`order_expire_date`, NEW.`item_id`, NEW.`item_cnt`, NEW.`order_status`, NEW.`tran_amount`)
-
2018-04-07T02:03:33 Created triggers OK.
-
2018-04-07T02:03:33 Copying approximately 1000219 rows...
-
INSERT LOW_PRIORITY IGNORE INTO `test`.`_item_order_new` (`order_id`, `loc_id`, `order_create_date`, `order_expire_date`, `item_id`, `item_cnt`, `order_status`, `tran_amount`) SELECT `order_id`, `loc_id`, `order_create_date`, `order_expire_date`, `item_id`, `item_cnt`, `order_status`, `tran_amount` FROM `test`.`item_order` FORCE INDEX(`PRIMARY`) WHERE ((`order_id` >= ?)) AND ((`order_id` <= ?)) LOCK IN SHARE MODE /*pt-online-schema-change 5178 copy nibble*/
-
SELECT /*!40001 SQL_NO_CACHE */ `order_id` FROM `test`.`item_order` FORCE INDEX(`PRIMARY`) WHERE ((`order_id` >= ?)) ORDER BY `order_id` LIMIT ?, 2 /*next chunk boundary*/
-
2018-04-07T02:05:07 Copied rows OK.
-
2018-04-07T02:05:07 Swapping tables...
-
RENAME TABLE `test`.`item_order` TO `test`.`_item_order_old`, `test`.`_item_order_new` TO `test`.`item_order`
-
2018-04-07T02:05:10 Swapped original and new tables OK.
-
2018-04-07T02:05:10 Dropping old table...
-
SET foreign_key_checks=0
-
DROP TABLE IF EXISTS `test`.`_item_order_old`
-
2018-04-07T02:05:11 Dropped old table `test`.`_item_order_old` OK.
-
2018-04-07T02:05:11 Dropping triggers...
-
DROP TRIGGER IF EXISTS `test`.`pt_osc_test_item_order_del`;
-
DROP TRIGGER IF EXISTS `test`.`pt_osc_test_item_order_upd`;
-
DROP TRIGGER IF EXISTS `test`.`pt_osc_test_item_order_ins`;
-
2018-04-07T02:05:11 Dropped triggers OK.
-
# Event Count
-
# ====== =====
-
# INSERT 727
-
Successfully altered `test`.`item_order`.
-
- 1 row in set (0.00 sec)
語句執行完成
[root@MySQL01 script]# python2.6 inception.py
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | 2 | EXECUTED | 0 | Execute Successfully
Backup successfully | None |
備份及回滾語句的生成條件:
線上伺服器必須要開啟 binlog,在啟動時需要設定引數log_bin、log_bin_index等關於 binlog 的引數。不然不會備份及生成回滾語句。
引數binlog_format必須要設定為 mixed 或者 row 模式。
引數 server_id 必須要設定為非0及非1。
-
mysql> show global variables like '%log%bin%';
-
+---------------------------------+------------------------------------+
-
| Variable_name | Value |
-
+---------------------------------+------------------------------------+
-
| log_bin | ON |
-
| log_bin_basename | /mysql_56_3306/log/mysql-bin |
-
| log_bin_index | /mysql_56_3306/log/mysql-bin.index |
-
| log_bin_trust_function_creators | ON |
-
| log_bin_use_v1_row_events | OFF |
-
| sql_log_bin | ON |
-
+---------------------------------+------------------------------------+
-
6 rows in set (0.00 sec)
-
-
mysql> show global variables like 'binlog_format';
-
+---------------+-------+
-
| Variable_name | Value |
-
+---------------+-------+
-
| binlog_format | ROW |
-
+---------------+-------+
-
1 row in set (0.00 sec)
-
-
mysql> show global variables like 'server_id';
-
+---------------+-------+
-
| Variable_name | Value |
-
+---------------+-------+
-
| server_id | 102 |
-
+---------------+-------+
- 1 row in set (0.00 sec)
檢視備份表
-
mysql> show databases;
-
+--------------------------+
-
| Database |
-
+--------------------------+
-
| information_schema |
-
| 192_168_56_101_3306_test |
-
| inception |
-
| mysql |
-
| performance_schema |
-
| sale |
-
| test |
-
+--------------------------+
-
8 rows in set (0.00 sec)
-
-
mysql> use 192_168_56_101_3306_test
-
Reading table information for completion of table and column names
-
You can turn off this feature to get a quicker startup with -A
-
-
Database changed
-
mysql> show tables;
-
+------------------------------------+
-
| Tables_in_192_168_56_101_3306_test |
-
+------------------------------------+
-
| $_$inception_backup_information$_$ |
-
| item_order |
-
+------------------------------------+
-
2 rows in set (0.00 sec)
-
-
mysql> select * from item_order;
-
+----+-----------------------------------------------------+-----------------+
-
| id | rollback_statement | opid_time |
-
+----+-----------------------------------------------------+-----------------+
-
| 1 | ALTER TABLE `test`.`item_order` DROP COLUMN `loc5`; | 1523037912_28_1 |
-
+----+-----------------------------------------------------+-----------------+
- 1 row in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2152755/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql稽核平臺yearning及inception安裝MySql
- Mysql安裝使用教程MySql
- windows安裝使用mysqlWindowsMySql
- Linux安裝MySQL(使用yum)LinuxMySql
- Linux下安裝使用MySQLLinuxMySql
- 如何使用APT庫安裝MySQLAPTMySql
- 使用docker安裝mysql和redisDockerMySqlRedis
- Navicat for MySQL安裝及使用教程MySql
- MySQL-01.Linux下MySQL安裝和使用MySqlLinux
- MYSQL安裝教程及sqlyog初次使用MySql
- CentOS下使用rpm包安裝MySQLCentOSMySql
- CentOS 7.0下使用yum安裝MySQLCentOSMySql
- 伺服器安裝docker 以及使用docker安裝mysql及svn伺服器DockerMySql
- 安裝mysqlMySql
- MySQL安裝MySql
- mysql 安裝MySql
- Linux安裝解除安裝MySQLLinuxMySql
- Linux使用原始碼來安裝MySQL 5.7Linux原始碼MySql
- 連網安裝mysql與原始碼安裝mysqlMySql原始碼
- 【MySQL安裝】Linux下安裝MySQL(預編譯)MySqlLinux編譯
- 【推薦 - glibc安裝】MySQL - 安裝MySql
- MySQL 8.0.21下載安裝教程及Navicat for MySQL安裝MySql
- 安裝mysql和mysql workbenchMySql
- RockyLinux安裝MySQLLinuxMySql
- ubuntu安裝MySQLUbuntuMySql
- Debian安裝MySQLMySql
- helm安裝mysqlMySql
- Ubuntu 安裝 mysqlUbuntuMySql
- Linux安裝MySQLLinuxMySql
- Docker 安裝mysqlDockerMySql
- MySQL安裝流程MySql
- Windows安裝mysqlWindowsMySql
- docker安裝mysqlDockerMySql
- macbook 安裝 mysqlMacMySql
- MySQL 的安裝MySql
- MySQL安裝配置MySql
- docker 安裝 mysqlDockerMySql
- MYSQL免安裝MySql