MySQL Dump Restoration when FOREIGN_KEY_CHECKS=0

foreign keyMySQLmysqldump

I currently use a SaaS DBMS. Backups of my database are provided to me in the form of a MySQL dump, and I noticed that FOREIGN_KEY_CHECKS=0. I am annoyed by this because it appears that this dump is not actually conducive to a restoration of the database(including relationships) on my end should the need arise.

Upon review of the structure I see that there are no Foreign Keys in the tables, but I see there are KEYS(indexes) that appear to correspond with what the foreign keys should be.

When performing a MySQL dump, does setting FOREIGN_KEY_CHECKS=0 mean that there are no relationships/foreign keys included in the dump?

Is it true that when restoring a MySQL dump that had FOREIGN_KEY_CHECKS=0 at the time of the dump , the foreign key relationships will not be present?

Is there a way to create foreign key relationships from the existing KEYS?

Best Answer

That is a default option in mysqldump. As the name states it only disables the foreign key check, which is necessary. If you don't disable the check, you'll almost certainly run into foreign keys errors, unless the restore, coincidentally, honors the parent/child relationships in the sequence that it restored the tables in. Extremely unlikely. Mysqldump doesn't account for this.

Look at it this way. If your dump restore tries to restore a child table before its parent, it will see the rows as orphan records and the check will give an error.

As ypercube said. The dump file will contain a set command at the end to turn the check back on. It's also a session based variable.

To address your concern. No. The set command does not remove foreign keys from your tables.