Not a developer? Go to

Ask an Expert

MySQL socket error

Asked by nathan
Posted October 16, 2013, in Featured.

What is this error?

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

1 Answer

Charlie Gorichanaz

Charlie Gorichanaz on October 16, 2013, 2:48 p.m. Reply

Hi Nathan,

This error can have a number of causes.

This installation never worked

If you are setting up a new Movable Type installation or configuring MT on a new server, the most likely cause is incorrect database settings in your mt-config.cgi file. The correct settings depend on your hosting environment.

If your hosting provider does not allow console access to the server hosting the MySQL database, you will need to contact your host to verify the database details. If they do allow console access, you can verify the settings on a command line.

For example, your mt-config.cgi might contain these lines:

DBHost     localhost

Then you could connect to your database from a computer with a MySQL client installed by opening a terminal window and entering the command:

mysql -uUSERNAME -p -hlocalhost DATABASE_NAME;

You would then be prompted for your password, and if successful, you will end up with a prompt like mysql>. Then you can type exit; to close it.

If that does not work, you might get another error message that would help diagnose further.

This installation used to work

If the DBHost is set to localhost or, you are telling MT to connect to a MySQL server hosted on the same server. The error you reported could be caused by MySQL not running.

You can check if MySQL is running by entering commands like:

Debian or Ubuntu Linux:

/etc/init.d/mysql status

RedHat or Fedora:

/etc/init.d/mysqld status

If you get the same socket error, you can try stating MySQL by running the same commands but replacing “status” with “start”. If successful, try loading MT again.

Still having problems?

Possibly MySQL could have been reconfigured, or you have multiple copies of MySQL installed, or something else. The socket file might need to be pointed to a new location. This can get complicated and would require more troubleshooting, but you can find some ideas on the StackOverflow question “Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)”.

Give an Answer

Charlie Gorichanaz

Charlie joined Six Apart as a Japan based product manager for Movable Type in February 2014 after spending two years as a developer for 601am. Previously he was the web director of The Badger Herald while studying biochemistry at the University of Wisconsin-Madison.

Twitter: @CNG

Ask An Expert