Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 654
Vasseurth Avatar asked Jul 08 '11 02:07

Vasseurth


People also ask

How do I switch from SQLite to MySQL?

The quickest and easiest way to convert SQLite to MySQL is by exporting an SQL Database to a Dump File, and then importing the SQLite Dump into MySQL Database. You can export an SQLite Database to Dump File using the . dump command.

What database does Rails use by default?

Rails defaults to using a SQLite database when creating a new project, but you can always change it later.


2 Answers

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
like image 105
tybro0103 Avatar answered Oct 26 '22 08:10

tybro0103


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'
like image 26
Avram Avatar answered Oct 26 '22 10:10

Avram