Create new Rails with mysql default on database.yml

Hello, I'm trying to connect with a db in my app, but when I go on
config/database.yml the default db is sqlite3, how can I put the mysql
as default ?

# SQLite version 3.x
# gem install sqlite3

`rails new --help`

felipe@Felipe:~/rails_projects$ rails new --help
  rails new APP_PATH [options]

  -r, [--ruby=PATH] # Path to the Ruby binary of your
                                 # Default:
  -b, [--builder=BUILDER] # Path to a application builder (can be
a filesystem path or URL)
  -m, [--template=TEMPLATE] # Path to an application template (can
be a filesystem path or URL)
      [--skip-gemfile] # Don't create a Gemfile
      [--skip-bundle] # Don't run bundle install
  -G, [--skip-git] # Skip Git ignores and keeps
  -O, [--skip-active-record] # Skip Active Record files
  -S, [--skip-sprockets] # Skip Sprockets files
  -d, [--database=DATABASE] # Preconfigure for selected database
                                 # Default: sqlite3
  -j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript
                                 # Default: jquery
  -J, [--skip-javascript] # Skip JavaScript files
      [--dev] # Setup the application with Gemfile
pointing to your Rails checkout
      [--edge] # Setup the application with Gemfile
pointing to Rails repository
  -T, [--skip-test-unit] # Skip Test::Unit files
      [--old-style-hash] # Force using old style hash (:foo =>
'bar') on Ruby >= 1.9

Runtime options:
  -f, [--force] # Overwrite files that already exist
  -p, [--pretend] # Run but do not make any changes
  -q, [--quiet] # Supress status output
  -s, [--skip] # Skip files that already exist

Rails options:
  -h, [--help] # Show this help message and quit
  -v, [--version] # Show Rails version number and quit

    The 'rails new' command creates a new Rails application with a
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home

    Note that the arguments specified in the .railsrc file don't affect
    defaults values shown above in this help message.

    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
    See the README in the newly created application to get going.


No need to post the results -- they're the same for everybody :slight_smile:

Ok, but how I can make the mysql be default ?

Uh, well -- the reason I suggested running that command is that the
answer is in the output. :slight_smile:

To make
mysql the default when you run rails new you would have to
modify the rails code somewhere (If you cannot figure out where
on your own you should not try to modify it). To change the
database driver used on this particular instance modify
config/database.yml. Run rails new xx -d mysql to see what the
values in that file should be.

In 3.2 you can define .railsrc with custom command line options that will always apply to rails new

Wow, that’s great :slight_smile:

$ cat ~/.railsrc

-d postgresql

$ time rails new test_3_2
Using --skip-bundle -T -d postgresql from /home/peterv/.railsrc

real 0m0.134s
user 0m0.108s
sys 0m0.024s

My special thanks to "7039def6 (Guillermo Iguaran " for this :slight_smile:


Ok, I create a new project with rails new new_project -d mysql, but it
create as default database mysql2.. is correct ?

# MySQL. Versions 4.1 and 5.0 are recommended.

Yep. You need to use mysql2 gem in a rails 3 project to avoid encoding problems!