【MySQL】更改表的主键报错及解决办法

报错:

[HY000][3750] Unable to create or change a table without a primary key, when the system variable ‘sql_require_primary_key’ is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

出现场景:想要使用以下语句更改数据库的主键

alter table A
    drop primary key;

alter table A
    add primary key (id);

解决办法:把两条语句写成一条即可

alter table A
    drop primary key,
    add primary key (id);

相关推荐

  1. MySQL解决办法

    2024-01-20 00:18:02       58 阅读
  2. 南大通用创建,外,索引方法常见

    2024-01-20 00:18:02       61 阅读
  3. npm installERR code ETIMEDOUT解决办法

    2024-01-20 00:18:02       60 阅读
  4. Ubuntu中rosdep update解决办法

    2024-01-20 00:18:02       50 阅读
  5. React 项目解决办法收录

    2024-01-20 00:18:02       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-20 00:18:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-20 00:18:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-20 00:18:02       82 阅读
  4. Python语言-面向对象

    2024-01-20 00:18:02       91 阅读

热门阅读

  1. uniapp 学习笔记

    2024-01-20 00:18:02       59 阅读
  2. IDA Pro 7.7和8.3共用方案

    2024-01-20 00:18:02       52 阅读
  3. 小程序显示兼容处理,home键处理

    2024-01-20 00:18:02       46 阅读
  4. 年终总结:我的2023编程之旅

    2024-01-20 00:18:02       55 阅读
  5. 介绍 TensorFlow 的基本概念和使用场景

    2024-01-20 00:18:02       56 阅读
  6. 电阻式电流采样不准?(下篇)

    2024-01-20 00:18:02       63 阅读