如何将 MySQL 代码纳入源代码管理?
我知道我可以手动将所有 MySQL 代码复制到文件中,然后将这些文件放入源代码管理中。但是有什么办法可以自动执行此操作吗?
我想对存储过程执行此操作,但也对表/事件/触发器创建脚本执行此操作。
I know I can copy all my MySQL code manually to files and then put those files into source control. But is there any way to do this automatically?
I would like to do this to stored procedures, but also to table/event/trigger creation scripts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以创建数据更改触发器,这会将更改自动存储到某些源代码管理中。但是,没有自动方法来跟踪结构更改(表、存储过程等)。因此,最好的方法可能是转储数据库并将这些转储存储在源代码管理中。您可以定期执行此操作以使事情自动化。
You can create triggers on data change, which would store the change automatically to some source control. However there is no automatic way to track structure changes (tables, stored procedures and so on) this way. So probably the best way is to dump database and store these dumps in source control. You can do this periodically to automate the things.
根据 Michal 的回答,我到目前为止使用的解决方案是:
Based on Michal answer, the solution I am using so far is:
不太明白你想做什么。
看看Liquibase,也许它会满足你的需要......
Don't really understand what you'r trying to do.
Look at Liquibase, perhaps it will do what you need...
PHP
如果您处于 PHP 环境中,此脚本会将过程和函数存储在单独的 (PHP) 文件中,这些文件可用于生成它们并存储在存储库中。
确保 db 用户具有适当的权限。
PHP
If you are in a PHP environment this script will store the procedures and function in separate (PHP) files which can be use to generated them and stored in a repo.
Make sure the db user has the proper rights.