MySQL Import Database--turn FOREIGN KEY constraints on/off

Source: Internet
Author: User
Tags import database mysql import mysql import database

Today, when I export a database from the server with a SQL file, I find that the import failed, prompting the INSERT statement to execute the error.

When inserting data, the content has a foreign key association and cannot insert data.

You can set the MySQL foreign key constraint by setting the method.

MySQL method for starting and closing foreign KEY constraints (Foreign_key_checks)

To disable a FOREIGN KEY constraint:

  SET Foreign_key_checks=0;  

To enable foreign KEY constraints:

  SET Foreign_key_checks=1;  

To view the values of the current FOREIGN KEY constraint:

SELECT  @ @FOREIGN_KEY_CHECKS;  

When exporting a database with SQLyog, tick "set foreign_key_checks = 0"

You can automatically set the cancel and open foreign key constraints for an exported SQL file

Set off FOREIGN KEY constraints

/**/;

To open a FOREIGN key constraint

/**/;

  

MySQL Import Database--turn FOREIGN KEY constraints on/off

Related Article

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.