gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 23:58:45 24 4
gpt4 key购买 nike

我需要定期备份 MySQL 数据库脚本(不含数据)。而且我还想使用 git 将脚本连同源代码一起推送到服务器。我已经使用 git 完成了源代码的推送和 pull 。但我也想推送数据库脚本。如何使用 git 实现这一点?有任何想法吗?

最佳答案

我不确定 Git 是否是存储数据库备份的最佳位置,具体取决于数据库的预期增长方式。但是,如果希望将 SQL 备份存储在 Git 中,则可以使用 mysqldump 和 git 命令来完成,前提是从 git 存储库执行以下命令:

mysqldump -h <host> -u <user> -p <db_name> > <sql_file>
git add <sql_file>
git commit -m "Latest mysqldump"
git push

例如:

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

MySQL 文档中提供了更多选项:http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

关于mysql - 使用git将mysql数据库脚本推送到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30702021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com