业务运行一段时间,发现原来的主键设置并不合理,这个时候,想变更主键.这种需求在实际生产中还是蛮多的. 下面,看看pt-online-schema-change解决这类问题的处理方式. 首先,创建一张测试表 create table t2(c1 int primary key, c2 int); 构造测试数据 delimiter // create procedure p1() begin ; ; do ); ; then commit; end if; end while; end // del…
It is great to be able to build small utilities on top of an excellent RDBMS. Thank you MySQL. This is a small but complex utility to perform online schema change for MySQL. We call it OSC and the source is here. Some ALTER TABLE statements take too…
1.把主键定义为自动增长标识符类型 MySql 在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值.例如: )); insert into customers(name) values("name1"),("name2"); select id from customers; 以上sql语句先创建了customers表,然后插入两条记录,在插入时仅仅设定了name字段的值.最后查询表中id字段,查询结果为: 由此可见,一旦把…