Report this

What is the reason for this report?

MySQL error 2002 / Database error: connection failed!

Posted on November 22, 2014
Nick

By Nick

I host a roundcube installation as well as YOURLS, which both make use of MySQL databases. Everything worked very fine, up until yesterday evening; MySQL decided it was time to make a mess of things and refused to work! Since I host two of my websites on the same VPS, using the same MySQL installation, they both stopped working at once.

The errors I get on my websites are as follows:

Roundcube website: DATABASE ERROR: CONNECTION FAILED! Unable to connect to database.

YOURLS website: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

The YOURLS error gave more insight into my problem, so I googled MySQL socket error and got a few interesting suggestions. On Stack Overflow, they suggested to chmod 777 the mysql socket, add socket=/var/lib/mysql/mysql.sock to my.cnf, but none of this helps. However, one peculiarity I found is that MySQL starts working again after I restart it. Hmm, very strange. I’ll try and reinstall it, after all, and see what comes of it.

Please help, if you know how to solve this problem. Thank you!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This happend to 2 of my droplets too (yesterday evening)! How to fix it? I don’t think that adding a swap file will help.

I have the same problem in one of my droplet. I did a full update of the packages in my system. the mysql is up and running now.

sudo apt-get upgrade

It looks like MySQL crashed. That usually happens when your droplet runs our of memory.

Try adding a swap file to your droplet: How To Add Swap on Ubuntu 14.04 | DigitalOcean.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.