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

Fraser asked:

I’ve developed a website on the Silverstripe framework and deployed this to a digital ocean server using centos (7.0.1406) , mariadb (10.0.14) and apache (2.4.6). I’m somewhat of a novice when it comes to system admin so set up the server following instructions in the digital ocean community docs (

I’m randomly getting the following error when I try to connect to the site:

[Warning] mysqli::mysqli(): (HY000/2002): Can’t connect to local MySQL
server through socket ‘/var/lib/mysql/mysql.sock’ (111)


$this->dbConn = new MySQLi($parameters['server'], $parameters['username'], $parameters['password']);

When this occurs, I reboot the server (with ‘reboot’) the issue goes away. It only seems to occur with activity is happening in the CMS. My client has experienced it a number of times when trying to upload images and I have just seen it for the first time when switching pages in the CMS.

No amount of use on the front end of the website causes issues (so far at least). What could be causing this issue? Are there any actions which can be performed by a website (PHP) that could trigger this failure? Overuse of system resources/hang ups somewhere/timeouts? Where can I start my debugging process?

I’ve deployed numerous sites under similar environments in the past but have never encountered this except for forcing a shut down via the digital ocean control panel.

My answer:

111 means Connection refused. That is, nothing is listening to that socket.

This means that MariaDB is not running, or was configured to listen to some other socket (or none at all).

Check your MariaDB configuration to ensure you specified the socket correctly, then restart it.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.