如何使用mysqldump仅导出CREATE TABLE命令? [英] How do I use mysqldump to export only the CREATE TABLE commands?
问题描述
我正在尝试使用mysqldump
仅导出数据库模式-没有数据,没有其他SQL注释,仅导出CREATE TABLE
命令.这是到目前为止我得到的:
I'm trying to use mysqldump
to export only the DB schema -- no data, no additional SQL comments, just the CREATE TABLE
commands. Here's what I've got so far:
mysqldump -h localhost -u root -p --no-data --compact some_db
它几乎达到了我想要的目的,但是我想消除字符集"行(类似于下面示例输出中的前3行).有mysqldump
选项可以做到这一点吗?
It almost achieves what I want, but I'd like to eliminate the "character set" lines (those like the first 3 lines in the example output below). Is there a mysqldump
option to do that?
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `foo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`bar_id` int(11) DEFAULT NULL,
`bazz` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=369348 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `bar` (
...etc.
这是我的版本信息,以防万一:
Here's my version info, in case that matters:
mysqldump Ver 10.13 Distrib 5.1.34, for Win32 (ia32)
mysql Ver 14.14 Distrib 5.1.34, for Win32 (ia32)
推荐答案
这也使用了grep,但似乎可行:
This uses grep as well, but it seems to work:
mysqldump -d --compact --compatible=mysql323 ${dbname}|egrep -v "(^SET|^/\*\!)"
我正在使用:
版本10.11分发5.0.51a,用于 debian-linux-gnu(x86_64)
Ver 10.11 Distrib 5.0.51a, for debian-linux-gnu (x86_64)
这篇关于如何使用mysqldump仅导出CREATE TABLE命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!