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 had same error. Every time my EC2 server rebooted due to lack of memory. Mysql did not restart causing my websites to crash by showing "Error establishing a database connection" At first, I restart my server from WHM, that fixed the error immediately. The error return next time the server rebooted again. I also tried to ssh auto restart mysql database on boot commands, but that was not problem. All though my security group was setup to accept all traffic, I had to change my security group to include mysql, and reboot my instances to fix the error. I not sure if this will work for everyone with EC2. That worked for me
You did not indicate whether you are moving your blog from myolddomain.com to mynewdomain.com, and whether you are using normal WordPress or multi-site WordPress. But here are some tips that might help:
First, you need to make sure your wp-config.php is configured correctly (database server, username, password...)
Secondly, WordPress uses database to store some information about the current host, look at tables wp_site, wp_options,wp_sitemeta and replace all rows containing myolddomain.com by mynewdomain.com.
Make sure your EC2 security group is configured correctly.
This article might help, too.
Please click on the security group for your RDS instance.And click on the inbound >Edit add "All TCP" for 0.0.0.0/0
Increase ur swap memory in ec2 that solves the problem. http://digitizor.com/2011/02/06/create-swap-file-ubuntu-linux/
Got the same problem recently , I use the AWS free tier account. The ec2 instance is t2.micro, which has no swap pre-configured. When i installed wordpress stuff, the memory usage is always higher, even i do nothing. One day, i run a
sudo yum update
command, the bash show that-bash: fork: Cannot allocate memory
error. And my website always goterror establishing a database connection
too.I think the root cause is high memory usage. You can add swap memory following the instruction here: How do you add swap to an EC2 instance?
you might consider closing your ports.
In AWS you can do this in the Security Group. For example if you have SSH, HTTP and HTTPS ports open (22, 80 etc..) try closing them to only your IP address. (by default they are 0.0.0.0, open to everyone). You should especially do this for SSH port.
bots are always trying to gain access to open ports... hitting you thousands of times a day if not more to test if you have open vulnerabilities. Depending on the size of your instance, you may not be able to handle this traffic. this could be the source of your server constantly crashing.