openark对MySQL进行Online_DDL

1.用oak对表sbtest1做添加字段和增加索引的Online DDL

openark kit 提供一组小程序,用来帮助日常的 MySQL 维护任务,可代替繁杂的手工操作。

包括:

oak-apply-ri: apply referential integrity on two columns with parent-child relationship.
oak-block-account: block or release MySQL users accounts, disabling them or enabling them to login.
oak-chunk-update: Perform long, non-blocking UPDATE/DELETE operation in auto managed small chunks.
oak-kill-slow-queries: terminate long running queries.
oak-modify-charset: change the character set (and collation) of a textual column.
oak-online-alter-table: Perform a non-blocking ALTER TABLE operation.
oak-purge-master-logs: purge master logs, depending on the state of replicating slaves.
oak-security-audit: audit accounts, passwords, privileges and other security settings.
oak-show-limits: show AUTO_INCREMENT “free space”.
oak-show-replication-status: show how far behind are replicating slaves on a given master.

**原文链接: http://www.oschina.net/p/openark-kit**

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 安装 oak
cd /u01/tools
tar -xzvf openark-kit-196.tar.gz 
cd openark-kit-196

#安装时报错 ImportError: No module named MySQLdb
yum install MySQL-python
1.3 检查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.4 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.5 ONLINE_DDL后数据校验
 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)

mysql> select count(1) from new_sbtest1
    -> ;
+----------+
| count(1) |
+----------+
|   991001 |
+----------+
1 row in set (0.36 sec)

mysql> select count(1) from sbtest1
    -> ;
+----------+
| count(1) |
+----------+
|   991001 |
+----------+
1 row in set (0.36 sec)
1.6表切换
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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值