When I run a mysqldump command on my database and then try to import it, it fails as it attempts to create the tables alphabetically, even though they may have a foreign key
Beware of your MySQL client you use, with the mysql
command, no problem. Dumping:
% mysqldump -u ocp6 -pocp6 ocp6 --single-transaction --result-file=dump.sql
Restoring:
% mysql -u ocp6 -pocp6 ocp6 < dump.sql
Everything's fine.
With the use of another MySQL client (mycli in my situation) to restore the dump-file:
mysql ocp6@:(none)> \. dump.sql
[…]
(1005, 'Can\'t create table `ocp6`.`composition` (errno: 150 "Foreign key constraint is incorrectly formed")')
I assume that mycli do not understand conditional comments.