I am getting the error: "error establishing a database connection" after moving my wordpress blog to Amazon EC2. I've checked the wp-config.php file and settings are ok (localhost, password and username).
I've read many of the questions and answers here but nothing helped me.
I have shell access so I can check everything that you need me to do. Maybe I should look at the configuration file for phpmyadmin to see what db connection settings are there, because phpmyadmin works, but I don't know where it is.
Thanks
I solved this problem adding a swap to my instance:
If you need more than 1024 then change that to something higher.
To enable it by default after reboot, add this line to /etc/fstab:
To check if your instance is using swap run this command:
The result:
SwapTotal: 1048572 kB
SwapFree: 1048572 kB
For me just restarting the mysqld service worked. There was a hitch though, as soon as I executed
sudo service mysqld restart
the MySql service stopped but didn't start.sudo services mysqld start
gave a MySQL Deamon Failed to Start Error. I spent a lot of time trying to start the service but I guess the real culprit was the httpd service. I stopped the httpd servicesudo service httpd stop
. Now executesudo service mysqld restart
and bingo the wordpress site was back online(remember to start the httpd service). This sounds kind of lame but it worked, from what I figured out the MySQL DB stops for a number of reasons looking at the log and figuring out the actual reason is the only thing that works for me.I'm not sure which distribution your using so here's how I generally solve these types of issues.
1. install a program called nmap (it scans ports) 2. run 'nmap localhost' (replace localhost with whichever server is running your database if its not local) 3. check to see if your database(mysql) is running
If not, then do something to the effect of 'services mysqld restart' (this will restart the mysql daemon). If this fixes it, then look into have that service autostart. If you get an error with that command than you may not have mysql installed.
If the server keep crashing after restart maybe you should increase your memory, upgraded the server from t2.micro to t2.medium do the trick for me.
I got the same error for my website, I just rebooted my instance and voila, problem solved.
My case:
I am using amazon free tier, and some bot requested my website and due to the high number of connections, the sql database could not serve the load. I have hence installed the load balancer too :) Hope it helps
The error in DB connection could be due to the root passwords (if you are connecting from a browser). Rest your root passowrd by executing $mysql_secure_installation to Secure your database. In the first step press then you can specify a new password for root. Then all should work fine.