简体   繁体   English

使用git将mysql数据库脚本推送到服务器

[英]Push mysql database script to server using git

I need to take backup of MySQL database script(without data) periodically. 我需要定期备份MySQL数据库脚本(无数据)。 And also I want to push the script to server along with source code using git. 我也想使用git将脚本和源代码一起推送到服务器。 I already done push and pull the source code using git. 我已经使用git完成了推和拉源代码。 But I want to push the DB script too. 但是我也想推送数据库脚本。 How to achieve this using git? 如何使用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. 我不确定Git是否是存储数据库备份的最佳位置,具体取决于数据库的增长方式。 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: 但是,如果希望将SQL备份存储在Git中,如果从git repo中执行以下操作,则可以使用mysqldump和git命令来完成:

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 MySQL文档中提供了更多选项: http : //dev.mysql.com/doc/refman/5.6/en/mysqldump.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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