How do I dump MySQL file without Foreign Keys via command line?

后端 未结 3 869
予麋鹿
予麋鹿 2020-12-16 03:06

I need to export a large database without foreign keys. What is the command to do this?

This is what I tried but I know this is incorrect.

mysqldump         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 03:44

    From this SO thread:

    Can you automatically create a mysqldump file that doesn't enforce foreign key constraints?

    The mysqldump command included with MySQL 5.0.51 (and according to the change log versions since 4.1.1) does switch off foreign key checks. By default, mysqldump includes the following line at the top of the dump file:

    /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

    The /*!40014 ... */ syntax is a conditional comment that will be executed on MySQL 4.0.14 and later. The old foreign key checks setting is restored at the end of the dump file:

    /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

提交回复
热议问题