Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Generate a Rails Application

How to let ruby app know to use mysql instead of sqlite3?

In your video sqlite3 comes with ruby on rails app. I would like to use mysql. How I can do that? This is missing in this course.

4 Answers

David Gross
David Gross
19,443 Points

You can find and change sqlite to mysql in the config/database.yml file. Make sure you add mysql2 gem to your gem file. If you know before you start an app that you are going to be using mysql. You can do it in your terminal when creating a new app and it will add all the dependencies for you.

rails new app_name -d mysql
gem 'mysql2', '~> 0.3.16'
default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: whateverpasswordyouwant
  socket: /tmp/mysql.sock

  <<: *default
  database: daily_planner_development

# 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.
  <<: *default
  database: daily_planner_test
David Gross
David Gross
19,443 Points

You need to change the password to whatever your mysql password for your root access is. Or if you do not have a password for your mysql user Just keep your password blank. Also if you are not comfortable using mysql in your terminal I would recommend downloading an app called sequel pro for your database management.

mysql -u root -p
Enter password:
  password: whateverpasswordyouwant

Thanks, David! I did it but now when I look at mu localhost:3000 it gives me an error access denied for user. Mysql2:: Error

Thank you, David!