如何将数据从生产数据库迁移到开发数据库 (Rails 4)? [英] How do I migrate data from production db to development db (Rails 4)?

查看:46
本文介绍了如何将数据从生产数据库迁移到开发数据库 (Rails 4)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这听起来有点倒退!我一直在研究基于云的案例管理应用程序,并且正在研究支持票务功能.我们的开发数据库 (MySQL) 拥有与生产数据库相同的数据(这是一个非常大的应用程序).开发基本上是一个沙箱"环境,因此为什么开发数据库与生产数据库完全相同.今天早上,我在本地开发服务器中遇到了一个问题:

I know this one sounds kind of backwards! I've been working on a cloud-based case-management application, and was working on a support-ticketing feature. We have our development database (MySQL) that has all the same data as our production database (It's a very large app). Development is basically a "sandbox" environment, hence why the development db has all the same as the production db. This morning, I ran into a problem in my local development server for:

Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue.

好吧,尽管这样做没有任何意义.它出错了,因为它试图创建已经存在的表(我已经运行了我的迁移,功能在一天前完成了!一切都很好).

Alright, did that, even though it didn't make any sense. It err'd out, because it was trying to create tables that already existed (I had already ran my migrations, the features were completed a day ago! And everything worked great).

在我的开发服务器收到这条消息之前,我唯一做的就是取消注释一个完全注释掉的文件,以尝试修复 TinyMCE(/config/tinymce.yml,文本编辑器)的问题,然后是重新启动我的 Rails 开发服务器.所有这些文件都是一堆默认值和插件.当我看到问题时,我首先将它们全部注释掉.还是一样的错误.继续 rake db: 任务.

The only thing that I did the moment before I got this message in my development server was uncomment an entirely-commented-out file to try and fix problems with TinyMCE (/config/tinymce.yml, text editor), followed by restarting my rails dev server. All this file was, was a bunch of defaults and plugins. When I saw the problem, I first commented them all back out. Still the same error. Proceeded with rake db: tasks.

开始寻找答案..不断出错.犯了一个菜鸟错误,最终做了一个

Started looking for answers.. kept getting errors. Made a noob mistake, and ultimately did a

rake db:migrate:reset 

我知道它会以托管数据库为代价重建架构.这失败了..但我们确实在不止一个地方有数据库(因为它与生产相同.)此外,只是尝试将所有表带回来:

which I knew would rebuild the schema at the cost of hosing the db. This failed.. But we do have the db in more than one place (since it's the same as production.) Also, just to try and bring all the tables back:

rake db:schema:load

....在其中一张桌子上失败了

....failed on one of the tables anyway with

ActiveRecord::StatementInvalid: Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `login` USING btree ON `users` (`login`, `intranet_id`)

..并且所有成功创建的表都是空的(如预期的那样).我绝不是数据库专家(我的开发时间不长).想知道,有没有办法将整个生产数据库复制到开发数据库中?表、数据和所有.或者有什么其他建议?真的输了.

..and all the tables are empty (as expected) that were successfully created. I'm by no means a database pro (I haven't dev'd very long). Am wondering, is there a way to copy the entire production database into the devel database? Tables, data, and all. Or any other suggestions? Really lost on this one.

推荐答案

您可以使用 mysql_dump.

如果您连接到数据库,一切都在那里 - 您只需要转储整个数据库,然后再次转储到生产表中.

If you connect to the database everything is there - you just have to do a dump of the full database and then do the dump again into the production tables.

正如您清楚地看到的,您可以使用>"从数据库中输出,也可以使用<"导入.

As you clearly see you can output from the database with ">" and you can import with the "<".

这篇关于如何将数据从生产数据库迁移到开发数据库 (Rails 4)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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