关于MySQL创建表时Error 1005: Can't create table (errno: 121)的解决办法
来源:互联网 发布:淘宝刷手机 编辑:程序博客网 时间:2024/05/16 15:30
ERROR 1005: Can't create table (errno: 121)
errno 121 means a duplicate key error. Probably the table already exists in the InnoDB internal data dictionary, though the .frm file for the table has been deleted. This is the most common reason for getting errno 121 in table creation. Another possible reason is a name conflict in a foreign key constraint name. Constraint names must be unique in a database, like table names are.
意思是:
1、表名重复
2、以该名字命名的表之前创建过后来删除了,但是对应的.frm文件还留在磁盘上
3、主键名字在全数据库范围内不是唯一的
以上是在网上找到的错误相关信息。
结合今天折腾半天找到的问题根源,总结如下:
首先,排查外键是否是全局唯一
使用如下命令,将$database 替换为要查询的数据库
select concat(table_name, '.', column_name) as 'foreign key', concat(referenced_table_name, '.', referenced_column_name) as 'references' from information_schema.key_column_usage where table_schema='$database' and referenced_table_name is not null;
则进行第二步查询,是否是约束重名
SELECT constraint_name, table_nameFROM information_schema.table_constraintsWHERE constraint_type = 'FOREIGN KEY'AND table_schema = DATABASE()ORDER BY constraint_name;
经过以上两步,基本可以发现是否是全局命名冲突引起的建表失败。
我的错误就是全局范围内出现约束重名。
好坑啊
0 0
- 关于MySQL创建表时Error 1005: Can't create table (errno: 121)的解决办法
- MySQL ERROR 1005: Can't create table (errno: 150)解决办法
- MySQL ERROR 1005: Can't create table (errno: 150)解决办法
- MySQL ERROR 1005: Can’t create table (errno: 150)解决办法
- MySQL ERROR 1005: Can't create table (errno: 150)解决办法
- MySQL ERROR 1005: Can't create table (errno: 150)解决办法
- MySQL ERROR 1005: Can't create table (errno: 150)解决办法
- MySQL ERROR 1005: Can't create table (errno: 150)解决办法
- MySQL ERROR 1005: Can't create table (errno: 150)解决办法
- MySQL创建外键出现 ERROR 1005: Can't create table (errno: 150)解决办法
- mysql ERROR: Error 1005: Can't create table (errno: 121)
- MySQL 外键创建表失败 ERROR 1005 (HY000): Can't Create Table....(errno: 150)
- mysql创建表失败 ERROR 1005 (HY000): Can't create table (errno: 13)
- mysql建表出现Error Code : 1005;Can't create table 'table' (errno: 121)
- mysql 1005-Can't create table ''error:121&mysql error 1005 can't create table'<errno:150>
- Mysql create table failure: ERROR 1005 (HY000): Can't create table 'lams.attendance1' (errno: 121)
- MySQL ERROR 1005: Can't create table (errno: 150)解
- MySQL ERROR 1005: Can't create table (errno: 150)
- MFC小笔记之Socket套接字
- Time Profiler的使用
- Viewpager + 小点点导航的具体实现
- 分布式Hadoop安装入门(4)——安装Hadoop
- CF 509B(Painting Pebbles-贪心)
- 关于MySQL创建表时Error 1005: Can't create table (errno: 121)的解决办法
- 黑马程序员 JAVA基础 - 多线程(一)
- Android显示pdf
- 简单手势GestureDetector
- Java中static、final用法小结
- JSON与XML的区别比较
- mfc之ocx控件制作
- 工厂方法模式
- Android模拟位置实现