Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a new Ruby on Rails application using MySQL instead of SQLite

People also ask

Can I use MySQL instead of SQLite?

However, if you require scalability in terms of the number of database queries required, MySQL is the better choice. If you want any real degree of concurrency or require higher levels of security as well as user permissions management, MySQL wins over SQLite.

What database does Ruby on Rails use?

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


Normally, you would create a new Rails app using

rails ProjectName

To use MySQL, use

rails new ProjectName -d mysql

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: mysql2
  database: db_name_dev
  username: koploper
  password:
  host: localhost
  socket: /tmp/mysql.sock

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


For Rails 3 you can use this command to create a new project using mysql:

$ rails new projectname -d mysql

Go to the terminal and write:

rails new <project_name> -d mysql