mysql修改索引时,外键约束造成的奇怪问题_MySQL
Jun 01, 2016 pm 01:37 PMMysql外键
bitsCN.com
mysql修改索引时,外键约束造成的奇怪问题
事情是这样的,在Windows的mysql5.5 ,我想修改一个表的索引,于是执行
[sql]
ALTER TABLE practice_log DROP INDEX ix_practice_log_userid;
ALTER TABLE practice_log ADD INDEX ix_practice_log_userid(userid,practicetime);
但是报错:unable drop index 。。。: needed in a foreign key constraint
于是,强行把外键约束检查关闭:
[sql]
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE practice_log DROP INDEX ix_practice_log_userid;
ALTER TABLE practice_log ADD INDEX ix_practice_log_userid(userid,practicetime)
SET FOREIGN_KEY_CHECKS=1;
索引修改成功。
但是,问题来了。。。。。
重启数据库后,表 practice_log 不见了!
删除表practice_log,报错:表不存在;
建表,报错:表已存在!
这应该是mysql的bug。
解决办法:不要用SET FOREIGN_KEY_CHECKS=0;老老实实得删掉外键约束吧,再修改索引,搞定。
另外,约束影响性能,尽量不要用。
bitsCN.com

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What should I do if I can't delete a Windows system dll file? Tips for completely deleting stubborn dll files

Lossless Scaling on Steam Deck OLED runs games at up to 2x FPS

How to update the latest version of Bybit Exchange? Will there be any impact if it is not updated?

deepseek web version entrance deepseek official website entrance

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP?

How to insert data into a MySQL table using PHP?
