mysqldump - Export structure only without autoincrement(mysqldump - 仅导出结构而没有自动增量)
问题描述
我有一个 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 - 仅导出结构而没有自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:mysqldump - 仅导出结构而没有自动增量
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 无法解决整理冲突 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
