11

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.

2
  • Which OS are you running? You'll also need to edit your Gemfile. Commented Jul 8, 2011 at 2:15
  • Official docs: Active Record Migration Commented Jan 29, 2014 at 13:30

3 Answers 3

27

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
Sign up to request clarification or add additional context in comments.

4 Comments

What do you mean by my instance?
by instance I mean your own settings
It says thatt I can't use mysql 0.3.6 What is an earlier version that is 0.2.x
Can we change the database from sqlite to mysql after we have created the application? I forgot to put -d mysql at the beginning.
2

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'

1 Comment

This is intended to addresses Planetpluto's comment under tybro0103's answer. I would have responded with another comment but it appears that I don't have enough privilege points to do so.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.