简体   繁体   中英

Push mysql database script to server using git

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM