Reputation: 1055
I need to take backup of MySQL database script(without data) periodically. And also I want to push the script to server along with source code using git. I already done push and pull the source code using git. But I want to push the DB script too. How to achieve this using git? Any ideas?
Upvotes: 3
Views: 4419
Reputation: 5593
I'm not sure if Git is the best place to store a backup of a DB depending upon how the DB is expected grow. However if the desire is to store the SQL backup in Git, this can be done using mysqldump and git commands if the following is executed from a git repo:
mysqldump -h <host> -u <user> -p <db_name> > <sql_file>
git add <sql_file>
git commit -m "Latest mysqldump"
git push
For example:
mysqldump -h 127.0.0.1 -u mydbuser -p mydbschema > 'db/currentBackup.sql'
git add 'db/currentBackup.sql'
git commit -m "Latest mysqldump"
git push
More options are available in the MySQL documentation: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html
Upvotes: 2