How do I use mysqldump to export only the CREATE TABLE commands?

后端 未结 6 1446
情深已故
情深已故 2021-01-31 15:26

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 go

相关标签:
6条回答
  • 2021-01-31 15:57

    Here is the command to dump the schema without the character set and AUTO_INCREMENT.

    mysqldump -h localhost -u root -p --no-data  YOUR_DATABASE_HERE |egrep -v "(^SET|^/\*\!)" | sed 's/ AUTO_INCREMENT=[0-9]*\b//'
    

    Here is the command to dump the schema without the character set, AUTO_INCREMENT and the comments

    mysqldump -h localhost -u root -p --no-data --compact YOUR_DATABASE_HERE |egrep -v "(^SET|^/\*\!)" | sed 's/ AUTO_INCREMENT=[0-9]*\b//'
    
    0 讨论(0)
  • 2021-01-31 16:10

    Did you try the --skip-comments option mentioned in the manual? Does it help?

    http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_comments

    0 讨论(0)
  • 2021-01-31 16:10

    Use --skip-set-charset option.

    http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_set-charset

    0 讨论(0)
  • 2021-01-31 16:11
    mysqldump --compact --no-set-names --skip-opt --no-data DB | sed "/ SET /d"
    
    0 讨论(0)
  • 2021-01-31 16:19
    mysql> SHOW CREATE TABLE mytablename;
    
    0 讨论(0)
  • 2021-01-31 16:20

    This uses grep as well, but it seems to work:

    mysqldump -d --compact --compatible=mysql323 ${dbname}|egrep -v "(^SET|^/\*\!)"
    

    I'm using:

    Ver 10.11 Distrib 5.0.51a, for debian-linux-gnu (x86_64)

    0 讨论(0)
提交回复
热议问题