Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

development:
  <<: *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.
test:
  <<: *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:
 change 
  password: whateverpasswordyouwant
  to 
  password:  

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!