mysql之 openark-kit online ddl
MySQL工具集openark-kit (官方網站 ),內部包含很多小工具,在5.6之前用於實現online ddl操作,
本文以CentOS為作業系統,且預設作業系統中已經安裝Python環境。
1.0、 安裝openark-kit工具包
安裝Python模組包之MySQL-python,用於使用Python連線操作MySQL使用。
yum install -y MySQL-python
RPM安裝方式
獲得RPM包
執行命令 rpm -ivh openark-kit-196-1.noarch.rpm
TAR包安裝方式
獲取tar包
解壓tar包 tar -zxvf openark-kit-196.tar.gz -C /usr/local/openark-kit/
安裝openark-kit工具 python setup.py install
1.1 sysbench載入資料
/u01/sysbench-0.5/sysbench/sysbench --test=/u01/sysbench-0.5/sysbench/tests/db/insert.lua --oltp-table-size=1000000 --mysql-table-engine=innodb --mysql-user=root --mysql-password=root123 --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=replTestDB --max-requests=0 --max-time=60 --oltp-tables-count=2 --report-interval=10 --num_threads=2 prepare
/u01/sysbench-0.5/sysbench/sysbench --test=/u01/sysbench-0.5/sysbench/tests/db/insert.lua --oltp-table-size=1000000 --mysql-table-engine=innodb --mysql-user=root --mysql-password=root123 --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=replTestDB --max-requests=0 --max-time=60 --oltp-tables-count=2 --report-interval=10 --num_threads=2 run
1.2 檢查ONLINE_DDL表是否有外來鍵觸發器 有則刪除
** 透過 information_schema.key_column_usage**
SELECT TRIGGER_SCHEMA,TRIGGER_NAME,EVENT_OBJECT_SCHEMA,
EVENT_OBJECT_TABLE
FROM information_schema.TRIGGERS
WHERE event_object_schema = 'replTestDB';
Select * from information_schema.key_column_usage where
Referenced_table_schema='replTestDB' and
Referenced_table_name='sbtest1';
1.3 ONLINE_DDL
cd /u01/tools/openark-kit-196/scripts/
python oak-online-alter-table -u root --ask-pass -S /u01/mysql/my3306/run/mysql.sock -d replTestDB -t sbtest1 -g new_sbtest1 -a "add last_update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,add key last_update_time(last_update_time)" --sleep=300 --skip-delete-pass
1.4 ONLINE_DDL後資料校驗
select count(*) from sbtest1
union all
select count(*) from new_sbtest1;
mysql> desc new_sbtest1
-> ;
+------------------+------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+-------------------+-----------------------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| k | int(10) unsigned | NO | MUL | 0 | |
| c | char(120) | NO | | | |
| pad | char(60) | NO | | | |
| last_update_time | timestamp | NO | MUL | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+------------------+------------------+------+-----+-------------------+-----------------------------+
5 rows in set (0.02 sec)
1.5表切換
use replTestDB;
set names utf8;
rename table sbtest1 to old_sbtest1,new_sbtest1 to sbtest1;
mysql> SELECT TRIGGER_SCHEMA,TRIGGER_NAME,EVENT_OBJECT_SCHEMA,
-> EVENT_OBJECT_TABLE
-> FROM information_schema.TRIGGERS
-> WHERE event_object_schema = 'replTestDB';
+----------------+----------------+---------------------+--------------------+
| TRIGGER_SCHEMA | TRIGGER_NAME | EVENT_OBJECT_SCHEMA | EVENT_OBJECT_TABLE |
+----------------+----------------+---------------------+--------------------+
| replTestDB | sbtest1_AI_oak | replTestDB | sbtest1 |
| replTestDB | sbtest1_AU_oak | replTestDB | sbtest1 |
| replTestDB | sbtest1_AD_oak | replTestDB | sbtest1 |
+----------------+----------------+---------------------+--------------------+
3 rows in set (0.01 sec)
drop trigger sbtest1_AI_oak;
drop trigger sbtest1_AU_oak;
drop trigger sbtest1_AD_oak;
drop table old_sbtest1;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2217016/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL Online DDL詳解MySql
- MySQL DDL執行方式-Online DDL介紹MySql
- MySQL & MariaDB Online DDL 參考指南MySql
- MySQL 執行 Online DDL 操作報錯空間不足?MySql
- MySQL Online DDL導致全域性鎖表案例分析MySql
- 一個 MySQL 線上 DDL 工具 — pt-online-schema-changeMySql
- MySQL在其版本迭代後Online DDL功能發生了哪些變化?MySql
- MySQL 8.0 Reference Manual(讀書筆記81節-- InnoDB and Online DDL (1))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記82節-- InnoDB and Online DDL (2))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記83節-- InnoDB and Online DDL (3))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記84節-- InnoDB and Online DDL (4))MySql筆記
- 記錄一次 Online DDL 操作
- MySQL之資料定義語言(DDL)MySql
- MySQL(十三)DDL之庫和表的管理MySql
- MySQL DDL操作表MySql
- TiDB Online DDL 在 TiCDC 中的應用丨TiDB 工具分享TiDB
- 對比上次MySQL的DDLMySql
- 04 MySQL 表的基本操作-DDLMySql
- MySQL 線上DDL "gh-ost"MySql
- MySQL - DDL詳解(Data Definition Language)MySql
- mysql DDL時鎖表的排查MySql
- 詳談 MySQL 8.0 原子 DDL 原理MySql
- mysql 原生 線上DDL 的bug .MySql
- MySQL全面瓦解4:資料定義-DDLMySql
- MySQL5.7 InnoDB線上DDL操作MySql
- MySQL的DDL和DML操作語法MySql
- MySQL DDL Waiting for table metadata lock 解決MySqlAI
- MySQL線上DDL工具 gh-ostMySql
- 【Mysql】MySQL 5.6中如何定位DDL被阻塞的問題MySql
- MySQL入門---(一)SQL的DDL語句MySql
- MySQL 中如何定位 DDL 被阻塞的問題MySql
- MySQL修改大表工具pt-online-schema-change原理MySql
- MySQL:pt-online-schema-change原理及注意點(未完)MySql
- MySQL 5.6中如何定位DDL被阻塞的問題MySql
- MySQL 執行DDL語句 hang住了怎麼辦?MySql
- Mysql系列第四講 DDL常見操作彙總MySql
- Mysql DDL出現長時間等待MDL問題分析MySql
- MySQL中的DDL(Data Definition Language,資料定義語言)MySql