Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push mysql database script to server using git

Tags:

git

mysql

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?

like image 378
Anitha Avatar asked Sep 23 '26 22:09

Anitha


1 Answers

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

like image 189
Hazok Avatar answered Sep 25 '26 14:09

Hazok