Error: Ruby on Rails 3.2 Can’t connect to local MySQL server through socket

I got an error when running rake db:migrate to create database is:

Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

This is problem for wrong socket in databse.yml file

To solve this error first find your socket file

mysqladmin variables | grep socket

For me, this gives:

| socket              | /var/run/mysqld/mysqld.sock           

Then, add a line to your config/database.yml:

development:
  adapter: mysql2
  host: localhost
  username: root
  password: xxxx
  database: xxxx
  socket: /var/run/mysqld/mysqld.sock

This will solve this problem.

Advertisements

One thought on “Error: Ruby on Rails 3.2 Can’t connect to local MySQL server through socket

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s