SHOW VARIABLES LIKE 'innodb\_lock_wait_timeout'; SET SESSION innodb_lock_wait_timeout=1
SET SESSION lock_wait_timeout=60 SET SESSION wait_timeout=10000
innodb_lock_wait_timeout=1
lock_wait_timeout=60
wait_timeout=10000
2.收集MySQL信息
SHOW VARIABLES LIKE 'version%'
SHOW ENGINES
SHOW VARIABLES LIKE 'innodb_version'
SHOW VARIABLES LIKE 'innodb_stats_persistent'
SELECT @@SERVER_ID
SHOW GRANTS FOR CURRENT_USER()
SHOW FULL PROCESSLIST
SHOW GLOBAL STATUS LIKE 'Threads_running'
SHOW GLOBAL STATUS LIKE 'Threads_running'
SELECT CONCAT(@@hostname, @@port)
SHOW TABLES FROM `test2` LIKE 'test1'
SHOW TRIGGERS FROM `test2` LIKE 'test1'
二 正式开始
1.创建跟旧表一模一样的新表
CREATE TABLE `test2`.`_test1_new` (
`id` int(30) NOT NULL,
`name` char(27) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
2.在新表上修改表结构
ALTER TABLE `test2`.`_test1_new` modify name char(27) 3.创建触发器
CREATE TRIGGER `pt_osc_test2_test1_del` AFTER DELETE ON `test2`.`test1` FOR EACH ROW DELETE IGNORE FROM `test2`.`_test1_new` WHERE `test2`.`_test1_new`.`id` OLD.`id` #删除操作
CREATE TRIGGER `pt_osc_test2_test1_upd` AFTER UPDATE ON `test2`.`test1` FOR EACH ROW BEGIN DELETE IGNORE FROM `test2`.`_test1_new` WHERE !(OLD.`id` NEW.`id`) AND `test2`.`_test1_new`.`id` OLD.`id`;REPLACE INTO `test2`.`_test1_new` (`id`, `name`) VALUES (NEW.`id`, NEW.`name`) #更新操作
CREATE TRIGGER `pt_osc_test2_test1_ins` AFTER INSERT ON `test2`.`test1` FOR EACH ROW REPLACE INTO `test2`.`_test1_new` (`id`, `name`) VALUES (NEW.`id`, NEW.`name`) #插入操作
4.插入到旧表
EXPLAIN SELECT `id`, `name` FROM `test2`.`test1` LOCK IN SHARE MODE IGNORE INTO `test2`.`_test1_new` (`id`, `name`) SELECT `id`, `name` FROM `test2`.`test1` LOCK IN SHARE MODE /*pt-online-schema-change 6291 copy table*/ #有锁操作LOCK IN SHARE MODE
三 收尾工作
SHOW WARNINGS
SELECT @@SERVER_ID
In most cases the tool will refuse to operate unless a PRIMARY KEY or UNIQUE INDEX is present in the table. See --alter for details.
The tool refuses to operate if it detects replication filters. See --[no]check-replication-filters for details.
The tool pauses the data copy operation if it observes any replicas that are delayed in replication. See --max-lagfor details.
The tool pauses or aborts its operation if it detects too much load on the server. See --max-load and --critical-load for details.
The tool sets innodb_lock_wait_timeout=1 and (for MySQL 5.5 and newer) lock_wait_timeout=60 so that it is more likely to be the victim of any lock contention, and less likely to disrupt other transactions. These values can be changed by specifying --set-vars.