MySQL Configuration for Rails

As of Rails 2.0, when you use the rails command to generate a new project, the database.yml file in the configuration folder defaults to using SQLite instead of MySQL.

I still advocate using MySQL. Although it is more “heavyweight” to install (unless you’re using InstantRails on Windows, which installs everything quite easily), it has a few advantages over SQLite:

  1. Tools: MySQL has a rich set of GUI tools available to maintain your databases–everything from user and database administrator to a query browser. These make life much, much easier.
  2. Features: SQLite, since it aims to be lightweight, ignores certain features, such as renaming columns. This might mean that–if you don’t use migrations–you’ll run into these issues at times.

Really, it’s a matter of personal choice; but if you choose to use MySQL, you might find it annoying to try and find a sample configuration file that you can use! For convenience, here’s a sample (generated in a Rails 1.2 project):


development:
adapter: mysql
database: railsrocket_development
encoding: utf8
username: dev
password: dev
host: localhost

test:
adapter: mysql
database: railsrocket_test
encoding: utf8
username: dev
password: dev
host: localhost

production:
adapter: mysql
database: railsrocket_production
encoding: utf8
username: enterUserName
password: enterPassword
host: localhost

Aside from needing to enter your production-mode username and password, the only real change is using the UTF-8 encoding. (It makes life a little easier if you have a multilingual application.)

About Ashiq Alibhai

Ashiq Alibhai, PMP, has been a Rails aficionado since 2007, and developed web applications since early 2003, where he learned PHP in one summer. As the driving-force behind RailsRocket and the Launchpad project, he seeks to share the ease of development with Rails far and wide.
This entry was posted in Deployment, Development and tagged , , , . Bookmark the permalink.

2 Responses to MySQL Configuration for Rails

  1. Pingback: Recent URLs tagged Databases - Urlrecorder

  2. The YPI says:

    Thanks great stuff