I want to create my Rails application with MySQL, because I like it so much. How can I do that in the latest version of Rails instead of the default SQLite?

share|improve this question

13 Answers

up vote 29 down vote accepted

If you already have a rails project, change the adapter in the config/database.yml file to mysql and make sure you specify a valid username and password, and optionally, a socket:

development:
  adapter: mysql
  database: db_name_dev
  username: koploper
  password:
  host: localhost
  socket: /tmp/mysql.sock

Next, make sure you edit your Gemfile to include the mysql or mysql2 or activerecord-jdbcmysql-adapter (if using jruby).

share|improve this answer

Normally, you would create a new Rails app using

rails ProjectName

To use MySQL, use

rails new ProjectName -d mysql
share|improve this answer

Ror rails 3 use

$rails new projectname -d mysql
share|improve this answer
rails -d mysql ProjectName
share|improve this answer

If you are using rails 3 or greater version

rails new your_project_name -d mysql

if you have earlier version

rails new -d mysql your_project_name

So before you create your project you need to find the rails version. that you can find by

rails -v
share|improve this answer
$ rails --help 

is always your best friend

usage:

$ rails new APP_PATH[options]

also note that options should be given after the application name

rails and mysql

$ rails new project_name -d mysql

rails and postgresql

$ rails new project_name -d postgresql
share|improve this answer

You should use the switch -D instead of -d because it will generate two apps and mysql with no documentation folders.

  rails -D mysql project_name  (less than version 3)

  rails new project_name -D mysql (version 3 and up)

Alternatively you just use the --database option.

share|improve this answer

If you are creating a new rails application you can set the database using the -d switch like this:

rails -d mysql myapp

Its always easy to switch your database later though, and using sqlite really is easier if you are developing on a Mac.

share|improve this answer
rails new <project_name> -d mysql

OR

rails new projectname

Changes in config/database.yml

development:
  adapter: mysql2
  database: db_name_name
  username: root
  password:
  host: localhost
  socket: /tmp/mysql.sock
share|improve this answer

In Rails 3, you could do

$rails new projectname --database=mysql
share|improve this answer

In the terminal write:

rails new -d mysql

share|improve this answer

Create application with -d option

rails new AppName -d mysql
share|improve this answer

Rails wiki always good for the very first layer configuration information.

http://newwiki.rubyonrails.org/database-support/mysql

share|improve this answer
1  
rails wiki is unmaintained and outdated – knoopx Jul 8 '10 at 11:40

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.