3

I know I can import a database dump like this:

mysql -u {{username}} -p {{target_database}} < myDump.sql

e.g.

mysql -u root -p theDatabase < myDump.sql

But how to import a database with foreign key check turned off?

I searched the mysql help for helpful parameters, but I found none:

mysql --help | findstr "foreign"

Returns nothing

Black
  • 15,426
  • 32
  • 140
  • 232
  • Possible duplicate of [How to temporarily disable a foreign key constraint in MySQL?](https://stackoverflow.com/questions/15501673/how-to-temporarily-disable-a-foreign-key-constraint-in-mysql) – Nico Haase Jun 20 '18 at 16:13

1 Answers1

9

First edit your database file and put SET FOREIGN_KEY_CHECKS = 0; at beginning and SET FOREIGN_KEY_CHECKS = 1; at the end of the database file.

This will help turn off the foreign key checks while restoring and it will also turn on the checks after restoration.

Robert Mennell
  • 1,874
  • 10
  • 24
Ranvir
  • 171
  • 7