简体   繁体   English

如何有选择地导出github仓库的mysql数据

[英]How to selectively export mysql data for a github repo

We're an opensource project and would like to collaboratively edit our website through github public repo. 我们是一个开源项目,并希望通过github公共回购协作编辑我们的网站。

Any ideas on the best solution to export the mysql data to github, as mysql can hold some sensitive info in it, and how we can version the changes that happen in it ? 关于将mysql数据导出到github的最佳解决方案的任何想法,因为mysql可以包含一些敏感信息,以及我们如何对其中发生的更改进行版本化?

Answer is you don't hold data in the repo. 答案是你没有在回购中保存数据。 You may want to hold your ddl, and maybe some configuration data. 您可能想要保留您的ddl,也许还有一些配置数据。 But that's it. 但就是这样。 If you want to version control your data, there are other options. 如果要对数据进行版本控制,还有其他选项。 GIT isn't one of them GIT不是其中之一

Use a blog engine "backend-ed by git", forget about mysql, commit on github.com, push and pull, dominate ! 使用博客引擎“git后端编辑”,忘记mysql,在github.com上提交,推拉,支配!

Here it is a list of the best: 这是最好的列表:

  1. http://jekyllrb.com/ http://jekyllrb.com/
  2. http://nestacms.com/ http://nestacms.com/
  3. http://cloudhead.io/toto http://cloudhead.io/toto
  4. https://github.com/colszowka/serious https://github.com/colszowka/serious

and just in case, ... a simple, Git-powered wiki with a sweet API and local frontend. 以及万一,...一个简单的,Git驱动的wiki,带有甜蜜的API和本地前端。 :

Assuming that you have a small quantity of data that you wish to treat this way, you can use mysqldump to dump the tables that you wish to keep in sync, check that dump into git, and push it back into your database on checkout. 假设您希望以这种方式处理少量数据,可以使用mysqldump转储要保持同步的表,检查转储到git中,并在结帐时将其推回到数据库中。

Write a shell script that does the equivalent of: 编写一个shell脚本,它相当于:

mysqldump [options] database table1 table2 ... tableN > important_data.sql

to create or update the file. 创建或更新文件。 Check that file into git and when your data changes in a significant way you can do: 将该文件检入git ,当数据发生重大变化时,您可以执行以下操作:

mysql [options] database < important_data.sql

Ideally that last would be in aa git post-receive hook, so you'd never forget to apply your changes. 理想情况下,最后一个将是一个git post-receive hook,所以你永远不会忘记应用你的更改。

So that's how you could do it. 这就是你如何做到的。 I'm not sure you'd want to do it. 我不确定你是否愿意这样做。 It seems pretty brittle, esp. 它似乎非常脆弱,尤其是 if Team Member 1 makes some laborious changes to the tables of interest while Team Member 2 is doing the same. 如果团队成员1对感兴趣的表做了一些费力的改动,而团队成员2也在做同样的事情。 One of them is going to check-in their changes first, and best case you'll have some nasty merge issues. 其中一个是首先检查他们的更改,最好的情况是你会有一些讨厌的合并问题。 Worst case is that one of them lose all their changes. 最糟糕的情况是,其中一人失去了所有的变化。

You could mitigate those issues by always making your changes in the important_data.sql file, but the ease or difficulty of that depend on your application. 您可以通过始终在important_data.sql文件中进行更改来缓解这些问题,但这样做的难易程度取决于您的应用程序。 If you do this, you'll want to play around with the mysqldump options so you get a nice readable, and git- mergable file. 如果你这样做,你要玩的mysqldump ,所以你得到一个不错的可读性和选项git-可合并文件。

似乎dbdeploy正是您所寻找的

You can export each table as a separate SQL file. 您可以将每个表导出为单独的SQL文件。 Only when a table is changed it can be pushed again. 只有在更改表格时才能再次按下。

If you were talking about configuration then I'd recommend sql dumps or similar to seed the database as per Ray Baxters answer. 如果您正在谈论配置,那么我建议使用sql转储或类似方法根据Ray Baxters答案为数据库设定种子。

Since you've mentioned Drupal, I'm guessing the data concerns users/ content. 既然你提到了Drupal,我猜这些数据与用户/内容有关。 As such you really ought to be looking at having a single database that each developer connects to remotely - ie one single version. 因此,您真的应该考虑拥有一个每个开发人员远程连接的单个数据库 - 即一个版本。 This is because concurrent modifications to mysql tables will be extremely difficult to reconcile (eg two new users both with user.id = 10 each making a new post with post.id = 1, post.user_id = 10 etc). 这是因为对mysql表的并发修改将非常难以协调(例如,两个新用户都使用user.id = 10,每个用户发布post.id = 1,post.user_id = 10等新帖子)。

It may make sense, of course, to back this up with an sql dump (potentially held in version control) in case one of your developers accidentally deletes something critical. 当然,使用sql转储(可能在版本控制中保留)来支持这一点可能是有意义的,以防一个开发人员意外删除了一些关键的东西。

If you just want a partial dump, PHPMyAdmin will do that. 如果您只想要部分转储,PHPMyAdmin将会这样做。 Run your SELECT statement and when it's displayed there will be an export link at the bottom of the page(the one at the top does the whole table). 运行SELECT语句,当它显示时,页面底部会有一个导出链接( 顶部的那个链接就是整个表格)。

You can version mysqldump files which are simply sql scripts as stated in the prior answers. 您可以对mysqldump文件进行版本控制,这些文件只是sql脚本,如前面的答案中所述。 Based on your comments it seems that your primary interest is to allow the developers to have a basis for a local environment. 根据您的意见,您的主要兴趣似乎是让开发人员拥有本地环境的基础。

Here is an excellent ERD for Drupal 6. I don't know what version of Drupal you are using or if there have been changes to these core tables between v6 and v7, but you can check that using a dump, or phpMyAdmin or whatever other tool you have available to you that lets you inspect the database structure. 这是Drupal 6的一个优秀的ERD。我不知道你正在使用什么版本的Drupal,或者v6和v7之间是否有这些核心表的更改,但你可以使用转储或phpMyAdmin或其他任何其他方法检查您可以使用的工具,可以让您检查数据库结构。 Drupal ERD Drupal ERD

Based on the ERD, the data that would be problematic for a Drupal installation is in the users, user_roles, and authmap tables. 基于ERD,Drupal安装存在问题的数据位于users,user_roles和authmap表中。 There is a quick way to omit those, although it's important to keep in mind that content that gets added will have relationships to the users that added it, and Drupal may have problems if there aren't rows in the user table that correspond to what has been added. 有一种省略这些的快速方法,但重要的是要记住,添加的内容将与添加它的用户有关系,如果用户表中没有与行对应的行,则Drupal可能会出现问题已被添加。

So to script the mysqldump, you would simply exclude the problem tables, or at very least the user table. 因此,要编写mysqldump脚本,您只需排除问题表,或至少排除用户表。

mysqldump -u drupaldbuser --password=drupaluserpw 0-ignore-table=drupaldb.user drupaldb > drupaldb.sql

You would need to create a mock user table with a bunch of test users with known name/password combinations that you would only need to dump and version once, but ideally you want enough of these to match or exceed the number of real drupal users you'll have that will be adding content. 您需要创建一个模拟用户表,其中包含一组具有已知名称/密码组合的测试用户,您只需要转储和版本一次,但理想情况下,您需要足够多的这些用户来匹配或超过真正的drupal用户数量将会增加内容。 This is just to make the permissions relationships match up. 这只是为了使权限关系匹配。

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

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