Question

MySQL error 2002 / Database error: connection failed!

  • Posted on November 22, 2014
  • nerdynickAsked 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!

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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

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.