目的

线上一张表的字段长度变更

`sGuid` varchar(255) DEFAULT NULL COMMENT 'sGuid'

=》

`sGuid` varchar(512) DEFAULT NULL COMMENT 'sGuid'

 

方法

pt-online-schema-change --user=xxxx--password=xxxxxx --host=127.0.0.1 --port=3306 \
--charset=utf8mb4 D=db_main,t=tb_main \
--alter "modify sGuid varchar(512) DEFAULT NULL COMMENT 'sGuid'" \
--no-check-alter --no-check-replication-filters --alter-foreign-keys-method=auto --recursion-method=none \
--critical-load="Threads_running=50" --max-load="Threads_running=100" \
--print --execute

执行时报错:

2019-07-25T11:03:00 Error copying rows from `db_main`.`tb_main` to `db_main`.`_tb_main_new`: 2019-07-25T11:03:00 Copying rows caused a MySQL error 1300:
    Level: Warning
     Code: 1300
  Message: Invalid utf8 character string: 'CE'

 

在 percona 官网找到原因: https://jira.percona.com/browse/PT-1528 ,这里直接贴出原因。

pt-online-schema-change could emit utf8 errors for binary PK:

Workaround specify latin1 charset for pt-o-s-c:

pt-online-schema-change --execute --charset=latin1 --chunk-size 2 --alter 'engine=innodb' D=test,t=brokenutf8alter

pt-o-s-c still processes the table correctly (utf8mb4 symbols stored in additional varchar field are valid after pt-o-s-c run). 4-byte changes also processed correctly by pt-o-s-c triggers.

Possible fix: use binary or hex literals instead of '?' substitution.

 

解决

用 latin1 字符集代替 utf8

pt-online-schema-change --user=xxxx--password=xxxxxx --host=127.0.0.1 --port=3306 \
--charset=latin1 D=db_main,t=tb_main \
--alter "modify sGuid varchar(512) DEFAULT NULL COMMENT 'sGuid'" \
--no-check-alter --no-check-replication-filters --alter-foreign-keys-method=auto --recursion-method=none \
--critical-load="Threads_running=50" --max-load="Threads_running=100" \
--print --execute

 

相关文章:

  • 2021-08-11
  • 2022-01-07
  • 2021-06-12
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2021-06-25
猜你喜欢
  • 2021-08-30
  • 2021-05-27
  • 2021-12-30
  • 2022-12-23
  • 2022-02-27
  • 2021-09-03
  • 2021-05-26
相关资源
相似解决方案