Ramblings of this guy you know!

Tech Stuff and random observations on life as I see it….

Misadventures in Computing – ERROR 2002: Can’t connect to local MySQL server through socket

Earlier today i came across a problem with one of the Ubuntu servers i manage that runs MYSQL. The system had just recovered from a sudden power failure and when we tried to access MYSQL we got the following error.

ERROR 2002: Can’t connect to local MySQL server through socket ‘/var/run/mysql/mysql

This problem occurs when the file mysqld.sock doesn’t exist where it expect it to be.

The location it is going to look for the mysqld.sock file in the location specified by the debian.cnf file in /etc/mysql. You will need sudo rights to view this file

user@server:/etc/mysql$ sudo more debian.cnf
[sudo] password for user:
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = gibberish here
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = = gibberish here
socket = /var/run/mysqld/mysqld.sock
basedir = /usr

On this server it tells us to go look in /var/run/mysqld for the file.

This problem is quite easily fixed by simply creating a new mysqld.sock file by following the steps below:

Create the directory (if it doesn’t already exist).

sudo mkdir /var/run/mysqld

Create the file by “touching” it.

sudo touch /var/run/mysqld/mysqld.sock

Set the ownership of the mysqld.sock file and folder to mysql.

sudo chown -R mysql /var/run/mysqld/

Alternatively you can run the mysql_safe & command which will create a mysqld.sock file for you with the correct permissions.

Advertisements

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

%d bloggers like this: