pt-online-schema-change 使用基础7

2022-05-03 11:59:08 浏览数 (1)

非空报错

代码语言:javascript复制
[root@h101 ~]# pt-online-schema-change -u root -h localhost  -pmysql  --alter='add column newid2 char(20) not null ' --execute D=pt,t=forpttest  
No slaves found.  See --recursion-method if host h101.temp has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
Altering `pt`.`forpttest`...
Creating new table...
Created new table pt._forpttest_new OK.
Altering new table...
Altered `pt`.`_forpttest_new` OK.
2015-10-23T14:04:18 Creating triggers...
2015-10-23T14:04:18 Created triggers OK.
2015-10-23T14:04:18 Copying approximately 41 rows...
2015-10-23T14:04:18 Dropping triggers...
2015-10-23T14:04:18 Dropped triggers OK.
2015-10-23T14:04:18 Dropping new table...
2015-10-23T14:04:18 Dropped new table OK.
`pt`.`forpttest` was not altered.
2015-10-23T14:04:18 Error copying rows from `pt`.`forpttest` to `pt`.`_forpttest_new`: 2015-10-23T14:04:18 Copying rows caused a MySQL error 1364:
    Level: Warning
     Code: 1364
  Message: Field 'newid2' doesn't have a default value
    Query: INSERT LOW_PRIORITY IGNORE INTO `pt`.`_forpttest_new` (`id`, `name`, `comment`, `abc`, `newid`) SELECT `id`, `name`, `comment`, `abc`, `newid` FROM `pt`.`forpttest` LOCK IN SHARE MODE /*pt-online-schema-change 6366 copy table*/

[root@h101 ~]# 

如果新添列有非空约束,但不给定默认值,就会报错

Note: If you add a column without a default value and make it NOT NULL, the tool will fail, as it will not try to guess a default value for you; You must specify the default.

0 人点赞