将 Ruby on Rails 应用程序从 sqlite 转换为 MySQL? [英] Convert a Ruby on Rails app from sqlite to MySQL?

查看:37
本文介绍了将 Ruby on Rails 应用程序从 sqlite 转换为 MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Ruby on Rails 制作了一个应用程序,现在我想托管它.但是,他们要求我使用 MySQL 并使用 sqLite3 进行设置.有什么办法可以转换成使用MySQL吗?

I made an app in Ruby on Rails and now I want to get it hosted. However, they require that I use MySQL and I set it up using sqLite3. Is there any way to convert it to use MySQL?

推荐答案

Step 0

为安全起见,我建议在虚拟机中尝试使用此技术.为自己省去一大堆心痛,然后构建一个虚拟机,检查您的代码,并拥有一个安全的游乐场,如果悲剧发生,您可以将其扔掉.

Step 0

To be safe, I recommend experimenting a bit with this technique in a virtual machine. Save yourself a bunch of heartache and build a virtual machine, check out your code, and have a safe playground that you can throw away if tragedy strikes.

备份您的 database.yml 文件.

Make a backup copy of your database.yml file.

(来自您的应用程序根目录)

(from your application root)

cp config/database.yml config.database.yml.sqlite3

备份您的数据

对于 Rails 3,安装 YAML DB gem:https://github.com/ludicast/yaml_db

For Rails 3, install the YAML DB gem: https://github.com/ludicast/yaml_db

对于 Rails 2.x,安装 YAML DB 插件:

For Rails 2.x install the YAML DB plugin:

脚本/插件安装git://github.com/adamwiggins/yaml_db.git

运行转储任务

rake db:dump

更新您的 config/database.yml 文件.你会发现像

Update your config/database.yml file. You will find entries like

development:
  adapter: sqlite3
  database: db/development.sqlite3
  timeout: 5000
test:
  adapter: sqlite3
  database: db/test.sqlite3
  timeout: 5000
production:
  adapter: sqlite3
  database: db/production.sqlite3
  timeout: 5000

将它们更改为

development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: **myapp_development**
  pool: 5
  username: **root**
  password: **supersecretpassword**
  **socket: /opt/local/var/run/mysql5/mysqld.sock**
test:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: **myapp_test**
  pool: 5
  username: **root**
  password: **supersecretpassword**
  socket: **/opt/local/var/run/mysql5/mysqld.sock**

production:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: **myapp_production**
  pool: 5
  username: **root**
  password: **supersecretpassword**
  socket: **/opt/local/var/run/mysql5/mysqld.sock**

请务必根据您的平台更新星号包围的值!套接字值仅适用于使用 MacPorts 的 Mac OSX.大多数 linux 版本不需要这个值.

Be sure to update the values surrounded by asterix as appropriate for your platform! The socket value is only good for Mac OSX using MacPorts. Most flavors of linux do not require this value.

如果您在以下步骤中遇到一些错误,您可能需要安装 mysql gem:

If you have some errors in the following step, you might have to install the mysql gem:

sudo gem install mysql

让 rake 创建你的数据库

Have rake create your database

rake db:create
rake db:schema:load

步骤 6

使用 YamlDb 将数据重新加载到 MySql

Step 6

Use YamlDb to reload your data into MySql

rake db:load

这篇关于将 Ruby on Rails 应用程序从 sqlite 转换为 MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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