我有一个 MySQL 数据库,我正在尝试找到一种仅导出其结构的方法,而没有自动增量值.mysqldump --no-data
几乎可以完成这项工作,但它保留了 auto_increment 值.有没有什么方法可以不使用 PHPMyAdmin(我知道它可以做到)?
I have a MySQL database and I am trying to find a way to export its structure only, without the auto increment values. mysqldump --no-data
would almost do the job, but it keeps the auto_increment values. Is there any way to do it without using PHPMyAdmin (that I know it can do it)?
你可以这样做:
mysqldump -u root -p -h <db-host> --opt <db-name> -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*//' > <filename>.sql
正如其他人提到的,如果您希望 sed
正常工作,请添加 g
(用于 g 局部替换)参数,如下所示:
As mentioned by others, If you want sed
to works properly, add the g
(for global replacement) parameter like this :
mysqldump -u root -p -h <db-host> --opt <db-name> -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*//g' > <filename>.sql
(这仅在您安装了 GUI 工具时才有效:mysqldump --skip-auto-increment
)
(this only works if you have GUI Tools installed: mysqldump --skip-auto-increment
)
没有用,有时会破坏命令.请参阅此SO 主题以获取解释.所以优化的答案是:
The is useless and sometimes will break the command. See this SO topic for explanations.
So the optimized answer would be :
mysqldump -u root -p -h <db-host> --opt <db-name> -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*//g' > <filename>.sql
这篇关于mysqldump - 仅导出结构而没有自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!