在MySQL数据库上使用版本控制(Git) [英] Using version control (Git) on a MySQL database

查看:403
本文介绍了在MySQL数据库上使用版本控制(Git)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名WordPress设计师/开发人员,他越来越多地使用版本控制,特别是Git,尽管我在某些项目中使用SVN。



将所有WordPress文件添加到我的回购站中是没有问题的,如果我想知道我可以.gitignore wp -config文件,但由于我是目前唯一的开发人员,而且这些项目都是封闭源代码,所以它确实没什么意义。

WordPress很大程度上依赖于数据库,像任何CMS一样,保留文本内容以及许多设置,具体取决于我使用的特定插件/主题配置。我想知道在数据库上使用版本控制的最佳方法是什么,如果甚至可能的话。我想我可以做一个SQL转储,虽然我的MySQL服务器在Windows上运行(阅读为:我不知道该怎么做),然后将SQL转储添加到我的存储库。但是,当我推送一些活的东西时,这会带来巨大的安全威胁。

有没有人接受这样做? 解决方案

你可以在git仓库中备份你的数据库。当然,如果你把数据放入二进制形式的git中,你将失去所有git使用差异(变化)有效存储数据的能力。所以最好的做法是:将数据以文本序列化格式存储。



mysqldump是一个合适的程序,可以帮助您做到这一点。尽管如此,它并不完美。如果有什么干扰项目的序列化顺序(例如,由于创建新表格等),那么人为的中断将进入diff。这会降低存储效率。你可以编写一个自定义的串行器来只改变序列化,但是你正在做git已经很擅长的努力工作。只要使用sql dump。



这就是说,你想要做的不是当开发人员谈论把数据库放在git中时通常意味着什么。例如,如果您阅读@eggyal发布的链接(链接to codinghorror ),你会发现实际上放在git中的是生成初始数据库所需的脚本。可能会有其他脚本,比如那些用干净状态填充数据库数据,或者用测试数据填充数据库的数据。所有这些sql脚本都是文本文件,与您从mysqldump获得的sql转储格式几乎相同。所以你没有理由不能用你的日常数据来这样做。


I am a WordPress Designer/Developer, who is getting more and more heavily involved with using version control, notably Git, though I do use SVN for some projects. I am currently using Beanstalk for my remote repo.

Adding all of the WordPress files to my repo is no problem, if I wanted to I know I could .gitignore the wp-config file, but since I'm the only developer, currently, and these projects are closed source, it really makes little sense.

WordPress relies heavily on the database, as any CMS does, to keep textual content, and many settings depending on the specific plugin/theme configuration I'm using. I'm wondering what the best way of using version control on the database would be, if it's even possible. I guess I could do a SQL dump, though my MySQL server is running on Windows (read as: I don't know how to do it), and then add the SQL dump to my repository. But when I push something live, that poses huge security threats.

Is there an accepted practice of doing this?

解决方案

You can backup your database within a git repository. Of course, if you place the data into git in a binary form, you will lose all of git's ability to efficiently store the data using diffs (changes). So the number one best practice is this: store the data in a text serialised format.

mysqldump is a suitable program to help you do this. It isn't perfect though. If anything disturbs the serialisation order of items (eg. as a result of creating new tables, etc.) then artificial breaks will enter into the diff. That will decrease the efficiency of storage. You could write a custom serialiser to serialise changes only -- but then you are doing the hard work that git is already good at. Just use the sql dump.

That being said, what you are wanting to do isn't what devs normally mean when they talk about putting the database in git. For instance, if you read the link posted by @eggyal (link to codinghorror) you will see that what is actually placed in git are the scripts needed to generate the initial database. There may be additional scripts, like those to populate the database data with a clean state, or to populate it with testing data. All such sql scripts are text files, and pretty much the same format as the sql dump you would get from mysqldump. So there's no reason you can't do it that way with your day-to-day data as well.

这篇关于在MySQL数据库上使用版本控制(Git)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆