DEV Community

StuartCreed
StuartCreed

Posted on

Exporting a sql database from phpmyadmin and copying it to your local machine when you have lots of foreign key constraints

Export sql file from phpmyadmin

Use the below to set the session foreign key checks to 0 temporarily.

mysql --init-command="SET SESSION FOREIGN_KEY_CHECKS=0;" -u root -p landstack < landstack.sql

Then log into your mysql and run the following to set the checks to back on:

SET FOREIGN_KEY_CHECKS=1;

Or

You can replace the first command with

mysql -u root -p landstack < landstack.sql

and do a custom export for phpmyadmin with the 'Disable Foreign Keys' button selected.

This is necessary otherwise you may receive a foreign key constraint error when importing the database.

Top comments (0)