Mysqldumper: Dumping each table separately

前端 未结 2 1981
情书的邮戳
情书的邮戳 2020-12-29 11:23

How can I dump each mysql table separately with mysqldump?

Background: I want to track those dumps with git and using the pre-commit hook

Example: I have a s

相关标签:
2条回答
  • 2020-12-29 11:50
    mysqldump -t -u [username] -p test mytable
    

    will dump the table 'mytable' from the database 'test'.

    If you want to automate the procedure, you will need to write a script, that selects the table_names from the schema for you and apply the operation above for each table. You can automate the git operations as well.

    0 讨论(0)
  • 2020-12-29 11:54

    This should work in a shell:

    for x in `mysql --skip-column-names -u [username] -p[password] [dbname] -e 'show tables;'`; do
         mysqldump -u [username] -p[password] [db name] $x > "$x.sql"
    done
    
    0 讨论(0)
提交回复
热议问题