Error establishing a database connection


#1

all my sites using EasyEngine are falling several times a week, with this error

Error establishing a database connection


#2

This can be cause for so many reason.

First check the basics:

  1. database, user, password are correct in wp-config.php (make sure you are using EE configure details or if you have setup your own).
  2. mysql user has correct permissions
  3. if using EE you don’t have another wp-config.php located in the web root. EE uses wp-config.php in the location above root. WordPress will look for it there if it can’t find anything in the root. Caught me out accidently when I uploaded everything.

Where to find MySQL username & Password?

Suppose you have run ee stack install. MySQL username and password are stored in.my.cnf file. The Location of file depends on which user runs ee stack install. i.eroot@vagrant-ubuntu-trusty-32:~# sudo ee stack install command creates file in home directory of sudo user i.e here in /home/harshad/.my.cnf and root@vagrant-ubuntu-trusty-32:~# ee stack install run with root user creates file at /root/.my.cnf location.

Since EasyEngine v3.3.5, the file .my.cnf isn’t created anymore. Instead, the new location file is /etc/mysql/conf.d/my.cnf.


#3

sorry missed the bit that it’s failing. So am assuming it works some of the time. Then I am not sure. Sounds like MySQL is become unreachable e.g. crashing etc.


#4

One other reason is MySQL runs out of memory and crashes.


#5