开发者

How do I change my database from SQLite to MYSQL in Rails

开发者 https://www.devze.com 2023-03-18 23:14 出处:网络
I know that you have开发者_运维百科 to change the database.yml but I don\'t know what to change it to and how to download MYSQL and all of that jazz.Gemfile:

I know that you have开发者_运维百科 to change the database.yml but I don't know what to change it to and how to download MYSQL and all of that jazz.


Gemfile:

gem 'mysql2'

config/database.yml

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: db_name_here
  pool: 5
  username: root
  password:
  host: localhost

Command line:

bundle install
rake db:create
rake db:migrate

Of course MySQL needs to be installed.

If you're creating a new project:

rails new app_name_here -d mysql


I ran into the same problem when trying to use the mysql2 gem with Rails 3.0.9. When I ran rake db:create after installing the mysql2 gem, it gave me these warnings:

WARNING: This version of mysql2 (0.3.6) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1

WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x

To specify that you only want to use the 0.2.x versions of mysql2, edit your Gemfile so that

gem 'mysql2'

becomes

gem 'mysql2', '~> 0.2.1'


As of Rails 6 a command has been added to do this automatically.

$ rails db:system:change --to=mysql
    conflict  config/database.yml
Overwrite /home/jim/Rails projects/myapp/config/database.yml? (enter "h" for help) [Ynaqdhm] y
       force  config/database.yml
        gsub  Gemfile
        gsub  Gemfile

Ref.: https://www.bigbinary.com/blog/rails-6-has-added-a-way-to-change-the-database-of-the-app

0

精彩评论

暂无评论...
验证码 换一张
取 消