mysql5.6.46在线修改表字段失败

环境:

centos7.5
mysql5.6.46
pt-online-schema-change3.2

现象:

测试表
mysql> create table bb(id int ,name varchar(100));
Query OK, 0 rows affected (0.12 sec)

[root@lineqi ~]# pt-online-schema-change --noversion-check --skip-check-slave-lag=d --user=root --password=Whayer1234 --port=13306 --alter “modify column name varchar(600)” --execute S=/data/mysql_13306/mysql.sock,D=yjgk,t=aa
bash: name: command not found…
字段name加上‘’或``会报错,直接去掉即可
再修改
[root@lineqi ~]# pt-online-schema-change --noversion-check --skip-check-slave-lag=d --user=root --password=Whayer1234 --port=13306 --alter “modify column name varchar(600)” --execute S=/data/mysql_13306/mysql.sock,D=yjgk,t=aa
No slaves found. See --recursion-method if host lineqi 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 yjgk.aa
Creating new table…
Created new table yjgk._aa_new OK.
Altering new table…
Altered yjgk._aa_new OK.
The new table yjgk._aa_new does not have a PRIMARY KEY or a unique index which is required for the DELETE trigger.
Please check you have at least one UNIQUE and NOT NULLABLE index.

2020-06-02T23:26:01 Dropping new table…
2020-06-02T23:26:01 Dropped new table OK.
yjgk.aa was not altered.
提示新表需要主键或唯一索引加上非空约束

成功示例如下:

测试表

mysql> create table bb(id int primary key,name varchar(100));
mysql> insert into bb values(1,‘aa’),(2,‘bb’);
修改字段
[root@lineqi ~]# pt-online-schema- --noversion-check --skip-check-slave-lag=d --user=root --password=Whayer1234 --port=13306 --alter “modify column name varchar(600)” --execute S=/data/mysql_13306/mysql.sock,D=qjqx,t=bb
No slaves found. See --recursion-method if host lineqi 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 qjqx.bb
Creating new table…
Created new table qjqx._bb_new OK.
Altering new table…
Altered qjqx._bb_new OK.
2020-06-02T23:29:48 Creating triggers…
2020-06-02T23:29:48 Created triggers OK.
2020-06-02T23:29:48 Copying approximately 2 rows…
2020-06-02T23:29:48 Copied rows OK.
2020-06-02T23:29:48 Analyzing new table…
2020-06-02T23:29:48 Swapping tables…
2020-06-02T23:29:48 Swapped original and new tables OK.
2020-06-02T23:29:48 Dropping old table…
2020-06-02T23:29:48 Dropped old table qjqx._bb_old OK.
2020-06-02T23:29:48 Dropping triggers…
2020-06-02T23:29:48 Dropped triggers OK.
Successfully altered qjqx.bb.

mysql> desc bb;
±------±-------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±------±-------------±-----±----±--------±------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(600) | YES | | NULL | |
±------±-------------±-----±----±--------±------+
添加字段

[root@lineqi ~]# pt-online-schema-change --noversion-check --skip-check-slave-lag=d --user=root --password=Whayer1234 --port=13306 --alter “add column col1 text” --execute S=/data/mysql_13306/mysql.sock,D=qjqx,t=bb
No slaves found. See --recursion-method if host lineqi 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 qjqx.bb
Creating new table…
Created new table qjqx._bb_new OK.
Altering new table…
Altered qjqx._bb_new OK.
2020-06-02T23:34:39 Creating triggers…
2020-06-02T23:34:39 Created triggers OK.
2020-06-02T23:34:39 Copying approximately 2 rows…
2020-06-02T23:34:39 Copied rows OK.
2020-06-02T23:34:39 Analyzing new table…
2020-06-02T23:34:39 Swapping tables…
2020-06-02T23:34:39 Swapped original and new tables OK.
2020-06-02T23:34:39 Dropping old table…
2020-06-02T23:34:39 Dropped old table qjqx._bb_old OK.
2020-06-02T23:34:39 Dropping triggers…
2020-06-02T23:34:39 Dropped triggers OK.
Successfully altered qjqx.bb.

mysql> desc bb;
±------±-------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±------±-------------±-----±----±--------±------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(600) | YES | | NULL | |
| col1 | text | YES | | NULL | |

总结:

1、pt-online-schema-change在线修改表,需要表中有主键
2、修改的字段加上‘’或``会报错,直接去掉即可
3、创建新的备份表是以 create table cc like bb这个方式
mysql> create table cc like bb;
uery OK, 0 rows affected (0.13 sec)

mysql> desc cc;
±------±------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±------±------------±-----±----±--------±------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(10) | YES | | NULL | |
| col1 | text | YES | | NULL | |
±------±------------±-----±----±--------±------+
4、pt-online-schema-change在线修改表,只有唯一索引也不行

mysql> create unique index idx_id on ff(id);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> insert into ff values(null,‘aa’),(1,‘bb’);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

[root@lineqi ~]# pt-online-schema-change --noversion-check --skip-check-slave-lag=d --user=root --password=Whayer1234 --port=13306 --alter "modify column name varchar(20) " --execute S=/data/mysql_13306/mysql.sock,D=qjqx,t=ff
No slaves found. See --recursion-method if host lineqi has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
………………
Altered qjqx._ff_new OK.
The new table qjqx._ff_new does not have a PRIMARY KEY or a unique index which is required for the DELETE trigger.
Please check you have at least one UNIQUE and NOT NULLABLE index.
2020-06-02T23:54:42 Dropping new table…
2020-06-02T23:54:42 Dropped new table OK.
qjqx.ff was not altere

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值