简体   繁体   English

Rails,如何将数据从开发sqlite3数据库迁移到生产MySQL数据库?

[英]Rails, how to migrate data from development sqlite3 database to production MySQL database?

With Rails, how do you migrate data from development sqlite3 database to production MySQL database? 使用Rails,如何将数据从开发sqlite3数据库迁移到生产MySQL数据库?

How to make it easier? 如何让它更容易?

You should use a gem like YamlDB . 你应该使用像YamlDB这样的宝石。 Install the Gem and then use the following rake tasks 安装Gem,然后使用以下rake任务

rake db:data:dump  
RAILS_ENV=production rake db:data:load 

The first command dumps the contents of dev database to a file called db/data.yml 第一个命令将dev数据库的内容转储到名为db/data.yml的文件中

Also, please remember that this must be used in addition to rake db:schema:dump|load tasks as this only ports the data assuming the schema is already in place 另外,请记住,除了rake db:schema:dump|load tasks之外必须使用它,因为这只会在假设架构已经到位的情况下移植数据

Assuming your database configurations are properly set up in config/database.yml, the following should get the database structure set up in production for you. 假设您的数据库配置已在config / database.yml中正确设置,以下内容应为您在生产中设置数据库结构。

Runs against development database by default: 默认情况下运行开发数据库:

rake db:schema:dump

Run this against your production database by virtue of the RAILS_ENV environment variable: 根据RAILS_ENV环境变量对生产数据库运行此命令:

rake RAILS_ENV=production db:schema:load

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

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