Error establishing a database connection - recurring (Ubuntu)

Posted November 24, 2013 13.7k views
After a reboot of the droplet, all works fine for a while. I'm in the 512 MB memory plan. I have 2 WP sites installed. A backup plugin is installed but running weekly. In addition, when I get the error, and check on the status of mysql I get this: mysql stop/waiting

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.

Submit an Answer
15 answers
Looks like your MySQL server is failing out, chances are you're running out of RAM. Check the logs for reasons as to why MySQL would be stopping.
by Etel Sverdlov
Varnish is an HTTP accelerator and a useful tool for speeding up a server, especially during a times when there is high traffic to a site. It works by redirecting visitors to static pages whenever possible and only drawing on the server itself if there is a need for an active process. This tutorial covers installing wordpress on a LEMP stack (with nginx instead of apache), and then installing varnish.
The logs are empty as far as I can see.
In addition, I've been watching the memory as I do certain things. The error is appearing again and this is what outputs when I "watch" memory

total used free shared buffers cached
Mem: 495 284 210 0 4 51
-/+ buffers/cache: 228 267
Swap: 0 0 0

It appears I have free memory! So could something else be causing the issue?
I am running Apache. Thanks for the suggestion(s) but I'm trying to figure out what is causing the issue and your answer doesn't provide that (maybe it does, but I'm new to VPS so it doesn't for me).

If anyone can expand on Pablo of vDevices answer to explain or has any other advice/answers to offer, I'd greatly appreciate it!
"... but I'm trying to figure out what is causing the issue ..."

Apache consumes a lot of a server's resources. MySQL can consume a lot of resources, particularly if your websites serve a lot of dynamic content. Put the two programs on the same server (particularly one with only 512MB of memory) and you'll be frustrated by timeout issues.

Memcache can lighten the load on MySQL. Swap provides MySQL (and the rest of the programs on your server) with more than the 512MB of memory you currently have available.

"... and your answer doesn't provide that ..."

Read the articles I cited for ya. If you're interested in learning more, check out WordPress Hosting: Apache or Nginx?.
I read both articles as I stated, it doesn't answer my question since when I do a memory check, I'm not using all of it as I posted above. Because of that, I'm not convinced it's a memory issue. It may very well be but if it was a memory issue - when the error appears, shouldn't the memory check show that it's all being used?
There is a specific mysql log file that you may want to look at if you haven't already. It should be under /var/log/mysql/mysqld.log for CentOS, but it can vary depending on distribution and setup. There may be some additional information there. Besides the memory allocation and the mysql logs, you may wish to have the wordpress installs be as clean as possible. I try to keep only a few plugins running and installed. I've seen folks have 20+ plugins and that can lead to problems.
The logs are empty. I have minimal plugins. I upgraded my droplet to the 1GB and I'm STILL having these issues.

So I stand by the fact that this isn't memory related. Again, I do a memory check and I'm NOT at capacity.
Check MySQL's error log:
sudo tail /var/log/mysql.err
Previous 1 2 Next