pt-online-schema-change 测试使用-包含生成测试数据

# 参考网址: https://www.2cto.com/database/201703/618280.html

一、简要描述

1、mysql创建测试表

drop table IF EXISTS t_user;
CREATE TABLE `t_user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`age` tinyint(4) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

2、生成测试数据

delimiter //
DROP PROCEDURE IF EXISTS proc_batch_insert;
CREATE PROCEDURE proc_batch_insert()
BEGIN
DECLARE pre_name BIGINT;
DECLARE ageVal INT;
DECLARE i INT;
SET pre_name=187635267;
SET ageVal=100;
SET i=1;
WHILE i <= 10000000 DO
INSERT INTO t_user(`name`,age,create_time,update_time) VALUES(CONCAT(pre_name,'@qq.com'),(ageVal+1)%30,NOW(),NOW());
SET pre_name=pre_name+100;
SET i=i+1;
END WHILE;
END // delimiter ;
call proc_batch_insert();

1、打印-增加列

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="add info varchar(500) comment '个人简历'"  --print

1、执行-增加列

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="add info varchar(500) comment '个人简历'"  --execute

# 2、打印-删除列

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop info"  --print

2、执行-删除列

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop info"  --execute

3、打印-增加索引

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop index idx_name"  --print

3、执行-增加索引

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="add index idx_name(name(12))"  --execute

4、打印-删除索引

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop index idx_name"  --print

4、执行-删除索引

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop index idx_name"  --execute

5、打印-修改列

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="modify name varchar(20) not null default '' comment '用户名'"  --print

5、执行-修改列

pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="modify name varchar(20) not null default '' comment '用户名'"  --execute

二、详细操作记录

1、打印-增加列

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="add info varchar(500) comment '个人简历'"  --print
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
Exiting without altering `db222`.`t_user` because neither --dry-run nor --execute was specified. Please read the tool's documentation carefully before using this tool.
[root@my3-224 ~]#

1、执行-增加列

[root@my3-224 opt]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="add info varchar(500) comment '个人简历'"  --execute
No slaves found. See --recursion-method if host my1-222 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
Altering `db222`.`t_user`...
Creating new table...
Created new table db222._t_user_new OK.
Altering new table...
Altered `db222`.`_t_user_new` OK.
2018-05-18T19:32:53 Creating triggers...
2018-05-18T19:32:54 Created triggers OK.
2018-05-18T19:32:54 Copying approximately 898443 rows...
2018-05-18T19:33:13 Copied rows OK.
2018-05-18T19:33:13 Analyzing new table...
2018-05-18T19:33:13 Swapping tables...
2018-05-18T19:33:14 Swapped original and new tables OK.
2018-05-18T19:33:14 Dropping old table...
2018-05-18T19:33:14 Dropped old table `db222`.`_t_user_old` OK.
2018-05-18T19:33:14 Dropping triggers...
2018-05-18T19:33:14 Dropped triggers OK.
Successfully altered `db222`.`t_user`.
[root@my3-224 opt]#

2、打印-删除列

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop info"  --print
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
Exiting without altering `db222`.`t_user` because neither --dry-run nor --execute was specified. Please read the tool's documentation carefully before using this tool.
[root@my3-224 ~]#

2、执行-删除列

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop info"  --execute
No slaves found. See --recursion-method if host my1-222 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
Altering `db222`.`t_user`...
Creating new table...
Created new table db222._t_user_new OK.
Altering new table...
Altered `db222`.`_t_user_new` OK.
2018-05-18T19:44:19 Creating triggers...
2018-05-18T19:44:20 Created triggers OK.
2018-05-18T19:44:20 Copying approximately 996723 rows...
2018-05-18T19:44:38 Copied rows OK.
2018-05-18T19:44:38 Analyzing new table...
2018-05-18T19:44:39 Swapping tables...
2018-05-18T19:44:39 Swapped original and new tables OK.
2018-05-18T19:44:39 Dropping old table...
2018-05-18T19:44:39 Dropped old table `db222`.`_t_user_old` OK.
2018-05-18T19:44:39 Dropping triggers...
2018-05-18T19:44:39 Dropped triggers OK.
Successfully altered `db222`.`t_user`.
[root@my3-224 ~]#

3、打印-增加索引

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="add index idx_name(name(12))"  --print
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
Exiting without altering `db222`.`t_user` because neither --dry-run nor --execute was specified. Please read the tool's documentation carefully before using this tool.
[root@my3-224 ~]#

3、执行-增加索引

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="add index idx_name(name(12))"  --execute
No slaves found. See --recursion-method if host my1-222 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
Altering `db222`.`t_user`...
Creating new table...
Created new table db222._t_user_new OK.
Altering new table...
Altered `db222`.`_t_user_new` OK.
2018-05-18T19:49:24 Creating triggers...
2018-05-18T19:49:24 Created triggers OK.
2018-05-18T19:49:24 Copying approximately 996723 rows...
Copying `db222`.`t_user`: 52% 00:27 remain
2018-05-18T19:50:20 Copied rows OK.
2018-05-18T19:50:20 Analyzing new table...
2018-05-18T19:50:20 Swapping tables...
2018-05-18T19:50:20 Swapped original and new tables OK.
2018-05-18T19:50:20 Dropping old table...
2018-05-18T19:50:20 Dropped old table `db222`.`_t_user_old` OK.
2018-05-18T19:50:20 Dropping triggers...
2018-05-18T19:50:20 Dropped triggers OK.
Successfully altered `db222`.`t_user`.
[root@my3-224 ~]#

4、打印-删除索引

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop index idx_name"  --print
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
Exiting without altering `db222`.`t_user` because neither --dry-run nor --execute was specified. Please read the tool's documentation carefully before using this tool.
[root@my3-224 ~]#

4、执行-删除索引

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="drop index idx_name"  --execute
No slaves found. See --recursion-method if host my1-222 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
Altering `db222`.`t_user`...
Creating new table...
Created new table db222._t_user_new OK.
Altering new table...
Altered `db222`.`_t_user_new` OK.
2018-05-18T21:42:45 Creating triggers...
2018-05-18T21:42:45 Created triggers OK.
2018-05-18T21:42:45 Copying approximately 996723 rows...
Copying `db222`.`t_user`: 61% 00:19 remain
2018-05-18T21:43:35 Copied rows OK.
2018-05-18T21:43:35 Analyzing new table...
2018-05-18T21:43:35 Swapping tables...
2018-05-18T21:43:35 Swapped original and new tables OK.
2018-05-18T21:43:35 Dropping old table...
2018-05-18T21:43:35 Dropped old table `db222`.`_t_user_old` OK.
2018-05-18T21:43:35 Dropping triggers...
2018-05-18T21:43:35 Dropped triggers OK.
Successfully altered `db222`.`t_user`.
[root@my3-224 ~]#

5、打印-修改列

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="modify name varchar(20) not null default '' comment '用户名'"  --print
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
Exiting without altering `db222`.`t_user` because neither --dry-run nor --execute was specified. Please read the tool's documentation carefully before using this tool.
[root@my3-224 ~]#

5、执行-修改列

[root@my3-224 ~]# pt-online-schema-change --host=192.168.65.128 --user=davie --password=davie123 --port=3306  D=db222,t=t_user  --charset=utf8mb4 --nocheck-replication-filters --chunk-size=10000 --sleep=0 --alter="modify name varchar(20) not null default '' comment '用户名'"  --execute
No slaves found. See --recursion-method if host my1-222 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
Altering `db222`.`t_user`...
Creating new table...
Created new table db222._t_user_new OK.
Altering new table...
Altered `db222`.`_t_user_new` OK.
2018-05-18T20:07:14 Creating triggers...
2018-05-18T20:07:14 Created triggers OK.
2018-05-18T20:07:14 Copying approximately 996723 rows...
2018-05-18T20:07:38 Copied rows OK.
2018-05-18T20:07:38 Analyzing new table...
2018-05-18T20:07:38 Swapping tables...
2018-05-18T20:07:38 Swapped original and new tables OK.
2018-05-18T20:07:38 Dropping old table...
2018-05-18T20:07:39 Dropped old table `db222`.`_t_user_old` OK.
2018-05-18T20:07:39 Dropping triggers...
2018-05-18T20:07:39 Dropped triggers OK.
Successfully altered `db222`.`t_user`.
[root@my3-224 ~]#

pt-online-schema-change 测试使用-包含生成测试数据的更多相关文章

  1. AppBoxFuture(四). 随需而变-Online Schema Change

      需求变更是信息化过程中的家常便饭,而在变更过程中如何尽可能小的影响在线业务是比较头疼的事情.举个车联网监控的例子:原终端设备上传车辆的经纬度数据,新的终端设备支持同时上传速度数据,而旧的车辆状态表 ...

  2. python测试框架&&数据生成&&工具最全资源汇总

    xUnit frameworks 单元测试框架frameworks 框架unittest - python自带的单元测试库,开箱即用unittest2 - 加强版的单元测试框架,适用于Python 2 ...

  3. schema change + ogg 变更手册

    Check OGG  until no data queuing in replication process:testRO:a)login  test5 –l oggmgrb)oggc)#ggsci ...

  4. Online Schema Change for MySQL

    It is great to be able to build small utilities on top of an excellent RDBMS. Thank you MySQL. This ...

  5. Spark2.2+ES6.4.2(三十一):Spark下生成测试数据,并在Spark环境下使用BulkProcessor将测试数据入库到ES

    Spark下生成2000w测试数据(每条记录150列) 使用spark生成大量数据过程中遇到问题,如果sc.parallelize(fukeData, 64);的记录数特别大比如500w,1000w时 ...

  6. Powerdesigner中如何生成测试数据

    设计表完成以后,我们需要生成一些测试数据,可以直接更新到数据库中,下面我们就来试试: 第一步:建立需要的Profiles测试文件,[Model]--[Test Data Profiles],如图所示: ...

  7. SQL Server中生成测试数据

    原文:SQL Server中生成测试数据 简介      在实际的开发过程中.很多情况下我们都需要在数据库中插入大量测试数据来对程序的功能进行测试.而生成的测试数据往往需要符合特定规则.虽然可以自己写 ...

  8. 通过 Python_Faker 生成测试数据

    通过 Python_Faker 生成测试数据 一.介绍 在软件需求.开发.测试过程中,有时候需要使用一些测试数据,针对这种情况,我们一般要么使用已有的系统数据,你不可能通过手工来生成(最傻的方法)可能 ...

  9. 使用Hypothesis生成测试数据

    Hypothesis是Python的一个高级测试库.它允许编写测试用例时参数化,然后生成使测试失败的简单易懂的测试数据.可以用更少的工作在代码中发现更多的bug. 安装 pip install hyp ...

随机推荐

  1. SQL 给视图赋权限

    授予表权限 创建视图 授予视图权限 测试权限 复杂程度: 初级 数据要求: 使用自备的数据 您可以使用 SQL 在企业级地理数据库中创建表和要素类的视图. 本主题中的示例显示如何使用 Microsof ...

  2. BZOJ2480Spoj3105 Mod&BZOJ1467Pku3243 clever Y——EXBSGS

    题目描述 已知数a,p,b,求满足a^x≡b(mod p)的最小自然数x. 输入     每个测试文件中最多包含100组测试数据.     每组数据中,每行包含3个正整数a,p,b.     当a=p ...

  3. BZOJ3724PA2014Final Krolestwo——欧拉回路+构造

    题目描述 你有一个无向连通图,边的总数为偶数.设图中有k个奇点(度数为奇数的点),你需要把它们配成k/2个点对(显然k被2整除).对于每个点对(u,v),你需要用一条长度为偶数(假设每条边长度为1)的 ...

  4. HDU 1556-Color the ball-树状数组

    树状数组的成段更新. 首先要明白,insert函数的意思是更新某一点值,query函数的意思是从起点到某一点的和. 更新[a,b]段时,在a点插入一个1,在b+1点插入一个-1.这时,query(a) ...

  5. BZOJ 4196 软件包管理器

    树链剖分 建树之后,安装软件就是让跟节点到安装的节点路径所有点权+1,卸载软件就是让一个节点和他的子数-1 要求变化数量的话直接求和相减就行啦(绝对值) 注意一点,一开始的lazyatag应该是-1, ...

  6. pip详解

    pip是一个安装和管理 Python 包的工具.python安装包的工具有easy_install, setuptools, pip,distribute等,pip是Python官方推荐的包管理工具 ...

  7. prufer序列

    介绍 其实是\(pr\ddot{u}fer\)序列 什么是prufer序列? 我们认为度数为\(1\)的点是叶子节点 有一颗无根树,每次选出编号最小的叶子节点,加到当前prufer序列的后面,然后删掉 ...

  8. Scratch 简单的小游戏 --- 碰碰球

    Scratch 简单的小游戏 --- 碰碰球 ================================ 积木脚本块的简要分类: 1. 角色 2. 背景 3. 角色和背景组成的场景 4. 挡板角 ...

  9. windows 路由转发

    netsh interface ipv6 install 将内网的2433端口转发到外网的11111端口netsh interface portproxy add v4tov4 listenaddre ...

  10. emwin之求解窗口坐标及大小的一种方法

    @2019-01-26 [小记] 使用函数 WM_GetWindowRectEx(hItem, &Rect),坐标就存储在对象 Rect 中,可用于一些默认创建的窗口