How can I backup/dump MYSQL database with foreign key constraints? I wanted to take the dump of the MySQL database with all the constraints on that database. The dump (.sql file) I am having right now don't show any reference key(foreign key) relationship.

I am taking the dump with following command:

  mysqldump -u root -p --no-data --compact db_doctor &gt; db_doctor_no_data.sql


What am I missing?
When using MyISAM as the engine of your table, mysql will &quot;ignore&quot; the foreign key constraint and let you go on, this is for compatibility reasons throughout all mysql engines.
The recommended engine to use foreign keys is InnoDB, and honestly, for 99% of cases InnoDB is better.
You can easily change all your database to use InnoDB instead of MyISAM:

add default_storage_engine = InnoDB to /etc/mysql/my.cnf (or equivalent)

modify existing tables with alter table my_table engine=innodb

to modify all tables you can try this more complex statement:
SELECT concat_ws(' ', 'alter table', t.table_name, 'engine=innodb')
FROM information_schema.tables t
WHERE t.table_type = 'base table'
  AND t.table_schema = 'my_db'
  AND t.engine != 'innodb'



Now all your foreign keys should be respected and when you use mysqldump you will se them.