Strange problem caused by foreign key constraints when mysql modifies Indexes

Source: Internet
Author: User


When mysql modifies an index, the foreign key constraint causes a strange problem. In mysql5.5 of Windows, I want to modify the index of a table, run www.2cto.com [SQL] ALTER TABLE practice_log DROP INDEX ix_practice_log_userid; ALTER TABLE practice_log ADD INDEX partition (userid, practicetime); but the error message is unable drop index... : Needed in a foreign key constraint. Therefore, the foreign key constraint check is forcibly disabled: [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; INDEX modification successful. Www.2cto.com, but the problem is ..... After the database is restarted, The practice_log table is missing! When you delete the practice_log table, the following error occurs: The table does not exist; when you create a table, the following error occurs: The table already exists! This should be a mysql bug. Solution: Do not use SET FOREIGN_KEY_CHECKS = 0. You must delete the foreign key constraint and modify the index. In addition, constraints affect performance and should not be used whenever possible.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.