如何通过命令行转储没有外键的MySQL文件? [英] How do I dump MySQL file without Foreign Keys via command line?

查看:59
本文介绍了如何通过命令行转储没有外键的MySQL文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要导出没有外键的大型数据库.这样做的命令是什么?

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 -u root -p DBNAME SET FOREIGN_KEY_CHECKS = 0; | gzip > database.sql.gzip

推荐答案

从此SO线程开始:

您能否自动创建一个不强制执行外键约束的mysqldump文件?

MySQL 5.0.51附带的mysqldump命令(并根据4.1.1之后的更改日志版本)确实关闭了外键检查.默认情况下,mysqldump在转储文件的顶部包含以下行:

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 */;

/*!40014 ... */语法是一个条件注释,将在MySQL 4.0.14及更高版本上执行.旧的外键检查设置将在转储文件的末尾恢复:

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 */;

这篇关于如何通过命令行转储没有外键的MySQL文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆