DEV Community

StuartCreed
StuartCreed

Posted on

1

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay