How to Solve Error establishing a database connection
Error establishing a database connection is a database connection problem that happens in wordpress websites, when we used more memory from our shared server or vps servers. The mysql server will stops & we will get a Error establishing a database in our wordpress websites.
when you do upgrade you had problems with images which I tried to resolve I then got the white screen. I am now back to
Error establishing a database connection
and if I try to use the admin page I receive
Error establishing a database connection
This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at mysql5.namesco.net. This could mean your host’s database server is down.
- Are you sure you have the correct username and password?
- Are you sure that you have typed the correct hostname?
- Are you sure that the database server is running?
If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.
How to solve this error Error establishing a database connection ?
- First, try contacting the hosting provider if the database server is online / if they have any other problem at their end, or they made any changes to your account, or if there are any limitations/restrictions, if the hosting package is set to Windows and not Linux, etc .
- Double check your wp-config.php file settings for the database name, database username and database password. This is where most errors occur.
- Then check that you don’t need to change the database host from "localhost" to something else. You can get that info from your hosting provider.
- Check you have actually created a database with the same database name as is in your wp-config.php file.
- Last, but not least, if all that information is correct your database probably has a problem with it, and you may need to contact your hosting provider.
- Do NOT re-install WordPress. Try re-uploading all files & folders – except the wp-content folder – from a fresh download of WordPress. Make sure that you delete the old copies of files & folder before uploading the new ones.
- You’ll also need to recreate your wp-config.php file but that shouldn’t be too difficult.
- Then run the upgrade manually via wp-admin/upgrade.php
Hope it will sove your Error establishing a database connection problem with wordpress
How to Protect WordPress from XML-RPC Attacks
WordPress is the most popular Content Management System. This popularity makes WordPress a perfect target for hackers. The most common attack faced by a WordPress site is XML-RPC attack.
Recognizing an XML-RPC Attack
1) Randomly “Error establishing database connection” error is displaying on the WordPress site.
2) “Out of memory” error in the web console.
3) “Cannot open the file no such file/directory” error in web server error log.
4) “POST /xmlrpc.php HTTP/1.0” error in webserver access log.
What is XML-RPC?
WordPress utilizes a remote execution call called XML-RPC that is used to exchange information between computer systems over a network. XML-RPC is a remote procedure call that uses HTTP for transport and XML for encoding. This functionality can be exploited to send thousands of brute force attack in a short time. Hackers try to login to WordPress admin portal using xmlrpc.php with any username/password. Xmlrpc.php allows hackers to guess hundreds of passwords with only 3 or 4 HTTP requests leading to a high database load. Then your WordPress site will randomly go down and parse the error “error establishing database connection”
Command to search XML-RPC attack in different Linux distribution
For apache on centos:
# grep xmlrpc /var/logs/httpd/access.log
For apache on Ubuntu:
# grep xmlrpc /var/logs/apache2/access.log
For cPanel server
# grep xmlrpc /home/username/logs/access.log
For nginx server:
# grep xmlrpc /var/logs/nginx/access.log
If the WordPress site is facing attack, then the output of the above command will be similar to
“POST /xmlrpc.php HTTP/1.0” 200 674 “-” “Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)”
Blocking XML-RPC attack
We can block XML-RPC attack in different ways.
1) Manually block the xmlrpc in the .htaccess file
Here you can deny the access of xmlrpc file from all users. Simply paste the following code in the .htaccess file in the website document root.
# Block WordPress xmlrpc.php requests
# END protect xmlrpc.php
2)Manually block xmlrpc in webserver document root.
For Apache paste the code in the configuration file.
For Nginx paste the below code in the configuration file.
After editing the configuration files you need to restart the webserver in order to enable the changes.
3) Installing Jetpack Plugin.
Jetpack plugin for WordPress will block the XML-RPC requests. After enabling the jetpack plugin, you will still see the XML-RPC entries in the web server access log. The plugin reduces the load on the database from these malicious logs.
Verify Attack diminution
After enabling Jetpack plugin, the XML-RPC content is still remaining on the access log of the web server. The plugin reduces the load of the database and the plugin will block the attacking IP addresses. If you manually block the XML-RPC in webserver configuration file or in the .htaccess file, your logs will still show the requests, but the resulting error code will be something other than 200. It will be 403,500 or 404. Then the result is similar to the code below.
“POST /xmlrpc.php HTTP/1.1” 403 291 “-”674 “-” “Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)”
By reducing the malicious XML-RPC traffic your WordPress site will be more secure and it consumes fewer system resources. As a result, the WordPress site stays online.
If you need any further assistance please contact our support department.