Edgars
Edgars

Reputation: 953

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

I have Rails 3 app on Justhost server. I am still working on it, but sometimes I get this error :

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

I checked similair questions: here

I tried this command mysqladmin variables | grep socket

Get this error

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'ecotec11'@'localhost' (using password: NO)'

Don't understand how that could happen. Because I haven't changed database.yml file for long time.

I checked my databases are in good condition, users and passwords are the same.

I tried to restart server with touch tmp/restart.txt no luck in here!

Upvotes: 2

Views: 8666

Answers (5)

Hector Ahs
Hector Ahs

Reputation: 21

This works for me:

cd /tmp <br/>
ln -s /opt/bitnami/mysql/tmp/mysql.sock

Upvotes: -1

matt_goodall
matt_goodall

Reputation: 81

Had a similar problem running rake db:migrate on the production server. Checking my database.yml file I had the correct path under the production settings, but I wasn't running migration under the appropriate environment.

So, running rake db:migrate RAILS_ENV=production fixed the issue for me.

Upvotes: 0

Radoslaw Wasiuk
Radoslaw Wasiuk

Reputation: 51

For me worked following:

cd /usr/local/var/mysql
sudo rm -r xxxx-MacBook-Air.local.err
sudo chown -R _mysql:_mysql /usr/local/var/mysql
sudo mysql.server start

Until now I dont know what causes problems with running mysql server. If I will find out I will let you know for sure :)

Cheers

Upvotes: 2

Prakarangs
Prakarangs

Reputation: 49

I ran into the same problem so i follow the steps from http://sraji.wordpress.com/2011/05/18/problem-solved-for-mysql2error-cant-connect-to-local-mysql-server-through-socket-tmpmysql-sock-2-in-rails-3/

I added the socket:path into my database.yml file. Now it runs smoothly. I hope this help someone.

cheers,

Upvotes: 2

Leandro Falc&#227;o
Leandro Falc&#227;o

Reputation: 91

Try reinstall mysql package to be enabled to set your configuration.

sudo apt-get install mysql-server --reinstall

If this doesn't allow you to reconfigure the package you can use

sudo dpkg-reconfigure mysql-server

Look on DigitalOcean how to configure your MySQL: https://www.digitalocean.com/community/articles/a-basic-mysql-tutorial

Upvotes: 4

Related Questions