# How do I switch sqlite3 to mysql on RoR

**URL:** <https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719>\
**Category:** Rails\
**Created:** [January 21, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719 "2008-01-21T17:26:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 21, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/1 "2008-01-21T17:26:22Z")

</div>

I am a newbie and just started to learn Ruby on Rails. I have installed  
both Ruby, Rails, and MySQL server on my Windows XP system. Whenever I  
run a Rails application, it always gives me an error stating "  
MissingSourceFile in SayController#index, no such file to load –  
sqlite3" and “This error occurred while loading the following files:  
sqlite3”. I don’t want to use sqlite3 database. What I want is to use  
MySQL database by default. How do I make it to connect MySQL database by  
default instead of looking for sqlite3?

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 21, 2008, 7:10pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/2 "2008-01-21T19:10:29Z")

</div>

On Jan 21, 2008 11:26 AM, Chilung T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am a newbie and just started to learn Ruby on Rails. I have installed  
> both Ruby, Rails, and MySQL server on my Windows XP system. Whenever I  
> run a Rails application, it always gives me an error stating "  
> MissingSourceFile in SayController#index, no such file to load –  
> sqlite3" and “This error occurred while loading the following files:  
> sqlite3”. I don’t want to use sqlite3 database. What I want is to use  
> MySQL database by default. How do I make it to connect MySQL database by  
> default instead of looking for sqlite3?

The key is in the config/database.yml file.

The default file should look something like this:

# SQLite version 3.x

# gem install sqlite3-ruby (not necessary on OS X Leopard)

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

# Warning: The database defined as ‘test’ will be erased and

# re-generated from your development database when you run ‘rake’.

# Do not set this db to the same as development or production.

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

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

This gives the database configuration for each of the three  
environments development, test and production.

For MySql you want something like

development:  
adapter: mysql  
encoding: utf8  
database: temp\_development  
username: root  
password:  
socket: /tmp/mysql.sock

# Warning: The database defined as ‘test’ will be erased and

# re-generated from your development database when you run ‘rake’.

# Do not set this db to the same as development or production.

test:  
adapter: mysql  
encoding: utf8  
database: temp\_test  
username: root  
password:  
socket: /tmp/mysql.sock

production:  
adapter: mysql  
encoding: utf8  
database: temp\_production  
username: root  
password:  
socket: /tmp/mysql.sock

This is for an OSX system, some of the details like socket: might be  
different on Windows.

For a new Rails project you can override the default by using the -d  
mysql option on the rails command. The way I got the above  
database.yml file was by entering

$rails -d mysql temp

and then copying the text from temp/config/database.yml

If you are using an IDE or other means to generate the Rails app on  
Windows rather than the command line, you’ll have to find someone with  
more Rails on Windows experience than I have to help.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 21, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/3 "2008-01-21T20:34:55Z")

</div>

On Jan 21, 2008 8:26 AM, Chilung T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> sqlite3". I don’t want to use sqlite3 database. What I want is to use  
> MySQL database by default. How do I make it to connect MySQL database by  
> default instead of looking for sqlite3?

Edit `#{RAILS_ROOT}/config/database.yml` appropriately

## HTH!

Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 21, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/4 "2008-01-21T22:41:47Z")

</div>

Rick Denatale wrote:

> For a new Rails project you can override the default by using the -d  
> mysql option on the rails command. The way I got the above  
> database.yml file was by entering
> 
> $rails -d mysql temp
> 
> and then copying the text from temp/config/database.yml

Thanks Rick for your detailed guidance.

I did follow the steps you indicated.

I used command “rake db:migrate” to create a schema.rb file under db  
directory successfully without any error.

Inside config/database.yml file I set

QUOTE  
development:  
adapter: mysql  
encoding: utf8  
database: music\_library\_development  
username: root  
password: xxxx  
host: localhost  
UNQUOTE

I created an album.rb file under under models directory by using the  
command “ruby script/generate model Album”.  
I created an admin\_controller.rb file under controllers directory by  
using the command “ruby script/generate controller Admin”. Inside the  
admin\_controller.rb file, I only added a line of “scaffold :album” and  
saved the file.  
I started the server by “ruby script/server” command.  
But when I went the Firefox browser and entered  
[http://localhost:3000/admin](http://localhost:3000/admin), it gave me “500 Internal Server Error”.  
What did I miss in these steps for my Windows XP system?

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 21, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/5 "2008-01-21T23:34:57Z")

</div>

The scaffold method has been deprecated in Rails 2.0.

On Jan 22, 2008 8:11 AM, Chilung T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> development:  
> I created an admin\_controller.rb file under controllers directory by
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 27, 2008, 7:08pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/6 "2008-01-27T19:08:47Z")

</div>

It was changed for 2.0.2

You must specify that you want to use mysql:

rails myApp -d mysql

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 27, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/7 "2008-01-27T18:38:07Z")

</div>

On Jan 21, 8:33 pm, “Hassan S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> Isnt this actually a little error in Rails?  
> I run Rails v 2.0.2.

When I type

rails --help

it says that mysql is the default for --database  
but still the database.yml will be setup for sqlite when creating a  
new application.  
Doesnt seem right to me?

/ grz01

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 27, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/8 "2008-01-27T19:29:27Z")

</div>

yes - and they forgot to update the helptext then? (rails --help)  
/grz01

On Jan 27, 7:08 pm, Jimmy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 27, 2008, 7:19pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/9 "2008-01-27T19:19:02Z")

</div>

SQLite was made the default in 2.0. They must have just missed the  
change in the documentation.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 28, 2008, 2:15am UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/10 "2008-01-28T02:15:18Z")

</div>

On 1/27/08, Phillip K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> SQLite was made the default in 2.0. They must have just missed the  
> change in the documentation.

The default actually changed in 2.0.2

> **[Rails 2.0.2: Some new defaults and a few fixes](https://rubyonrails.org/2007/12/17/rails-2-0-2-some-new-defaults-and-a-few-fixes)**
>
> Now that we have the big Rails 2.0 release out the door, it’s a lot easier to push out smaller updates more frequently. So that’s what we’re going to do. Rails 2.0.2 contains a bunch of smaller fixes to various bugs, no show-stopping action, just...

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [January 28, 2008, 2:16am UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/11 "2008-01-28T02:16:29Z")

</div>

I had intended on typing 2.0.x. I guess I’m not perfect either.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [June 23, 2008, 4:35pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/12 "2008-06-23T16:35:03Z")

</div>

Rick Denatale wrote:

> The key is in the config/database.yml file.  
> …  
> The default file should look something like this:
> 
> # SQLite version 3.x

…

> This gives the database configuration for each of the three  
> environments development, test and production.
> 
> For MySql you want something like  
> …
> 
> This is for an OSX system, some of the details like socket: might be  
> different on Windows.
> 
> For a new Rails project you can override the default by using the -d  
> mysql option on the rails command. The way I got the above  
> database.yml file was by entering
> 
> $rails -d mysql temp

that was fine, i got the problem in a snap, and even if i’m a newbie i’m  
appreciating so much ruby, and most of all ruby-people like you! 🙂  
i never find such a friendly and effective community! really!

Chilung T. wrote:  
…

> I did follow the steps you indicated.

so did i, and worked smoothly, on linux ubuntu!

thank a lot!!

_the nth_

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [June 10, 2011, 5:40pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/13 "2011-06-10T17:40:58Z")

</div>

Rick Denatale wrote in post #621001:

> On Jan 21, 2008 11:26 AM, Chilung T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > I am a newbie and just started to learn Ruby on Rails. I have installed  
> > both Ruby, Rails, and MySQL server on my Windows XP system. Whenever I  
> > run a Rails application, it always gives me an error stating "  
> > MissingSourceFile in SayController#index, no such file to load –  
> > sqlite3" and “This error occurred while loading the following files:  
> > sqlite3”. I don’t want to use sqlite3 database. What I want is to use  
> > MySQL database by default. How do I make it to connect MySQL database by  
> > default instead of looking for sqlite3?
> 
> The key is in the config/database.yml file.

For Rails 3, you also need to modify the ‘Gemfile’ in your Ror project  
folder

change this line  
gem ‘sqlite3-ruby’, :require =\> ‘sqlite3’  
to  
gem ‘mysql2’

Otherwise, just remove the whole project folder and recreate your  
project from scratch with the -d mysql switch  
e.g.  
rails new testproject -d mysql

Good luck.

---

<div class="post-metadata">

**Author:** ![chilung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9fc348/32.png) [@chilung](https://www.ruby-forum.com/u/chilung)\
**Post date:** [November 27, 2010, 9:37pm UTC](https://www.ruby-forum.com/t/how-do-i-switch-sqlite3-to-mysql-on-ror/126719/14 "2010-11-27T21:37:45Z")

</div>

installing bundler and adding mysql to gemfile totally works !

> **[Not able to create DataBase : "MySQL and Rails3" ?](http://techleap.blogspot.com/2010/11/not-able-to-create-database-mysql-and.html)**
>
> Not able to create DB : MySQL and Rails3 ? For all those who have migrated from Rails 2.3 to Rails 3 must be facing this one initial problem...
