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,上面操作会导致主从复制异常。

  • 相关阅读:
    python logging模块
    mysql数据库的导出与导入
    requests请求高德地图api
    navicat连接阿里云ESC里的数据库
    ubantu+nginx+uwsgi+django部署
    linux小命令
    部署完的Django项目升级为HTTPS
    python常用模块
    python基础18——二分法&面向过程&匿名函数
    emmm......就当练习了系列15
  • 原文地址:https://www.cnblogs.com/gaogao67/p/10598855.html
Copyright © 2011-2022 走看看