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 ActiveRecord Basics Migrations and Relationships Migrations

Ah Ren
Ah Ren
175 Points

can't connect to local MySQL server through socket '/tmp/mysql.sock'

failed to run command rake db:create.

Error message:

<Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)>

Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"MyStore_App_development"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"} (If you set the charset manually, make sure you have a matching collation)

<Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)>

Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"MyStore_App_test"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"} (If you set the charset manually, make sure you have a matching collation)

1- open biller folder on (sublime text ) . 2- then go to (database.yml ) file on config folder 3- write your password for (root'@'localhost ) that you use it on (MySQLWorkbench) program : 4- save (database.yml ) file

on (database.yml ) file

# MySQL.  Versions 5.0+ are recommended.
#
# Install the MYSQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem 'mysql2'
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
#
default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: ******************** write your password here 
  socket: /tmp/mysql.sock

development:
  <<: *default
  database: biller_development ```

And for mysql -uroot

mysql -uroot -p

it will ask for password ( the password is the same for your (root'@'localhost ) and same what you write it in (database.yml ) file ..) It is work with me 100% ..

2 Answers

Nelly Nelly
Nelly Nelly
7,134 Points

Hello !

I still have this, what am I doing wrong??

$ mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I've followed your suggestion

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: password1
  host: localhost

development:
  <<: *default
  database: biller_development

Nelly Nelly

the password should be the same in both (MySQLWorkbench) and database.yml

Nelly Nelly
Nelly Nelly
7,134 Points

Oh thanks ! I am just starting the database fundation tutorial I had skipped it ! It would help then :) I am having trouble with the workbench though :(