zoukankan      html  css  js  c++  java
  • MySQL Replication--修改主键为NULL导致的异常

    测试环境:
    MySQL 5.5.14/MySQL 5.6.36

    测试脚本:

    create table tb001(id int primary key,c1 int);
    alter table tb001 modify id int null;
    show create table tb001;

    建表语句为:

    CREATE TABLE `tb001` (
      `id` int(11) NOT NULL DEFAULT '0',
      `c1` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8

    上面ALTER命令想要将表主键ID列修改为null,执行完成未报错,但未修改成功。

    查看BINLOG日志发现:

    # at 696251545
    #190326 10:51:55 server id 2817457  end_log_pos 696251653 	Query	thread_id=9585927	exec_time=0	error_code=0
    SET TIMESTAMP=1553568715/*!*/;
    create table tb001(id int primary key,c1 int)
    /*!*/;
    # at 696251653
    #190326 10:52:00 server id 2817457  end_log_pos 696251752 	Query	thread_id=9585927	exec_time=0	error_code=0
    SET TIMESTAMP=1553568720/*!*/;
    alter table tb001 modify id int null
    /*!*/;

    发现该命令被记录到BINLOG日志中。

    上面代码在MySQL 5.7版本中执行,会报错:

    错误代码: 1171
    All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead

    如果主库为MySQL 5.5或MySQL 5.6,而从库为MySQL 5.7,上面操作会导致主从复制异常。

  • 相关阅读:
    luogu P1451 求细胞数量
    P1443 马的遍历
    luogu P1194 买礼物
    codevs 4919 线段树练习4
    printf的实型
    printf的整型
    scanf
    printf
    c++常用函数
    字符类型C++(ascll码表)
  • 原文地址:https://www.cnblogs.com/gaogao67/p/10598855.html
Copyright © 2011-2022 走看看