mysqldump - Export structure only without autoincrement

前端 未结 5 1894
太阳男子
太阳男子 2020-12-04 14:16

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 j

5条回答
  •  情书的邮戳
    2020-12-04 14:56

    You can do this :

    mysqldump -u root -p -h  --opt  -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*\b//' > .sql
    

    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  --opt  -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*\b//g' > .sql
    

    (this only works if you have GUI Tools installed: mysqldump --skip-auto-increment)

    New UPDATE thanks to comments.

    The \b 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  --opt  -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*//g' > .sql
    

提交回复
热议问题