For those admins or new to WordPress then the connection error to the WordPress database is not too strange. This error appears to make users very uncomfortable because it takes time to fix. In the following article, BKNS will share with you how to fix it error connecting to WordPress database quick and simple.
1. What is error connecting to WordPress database?
Error connecting to WordPress database (English name is: Error Establishing A Database Connection). This error appears when you use the WordPress source code, not because of the website, but because the server or configuration is incorrect. Some of the main causes identified as causing the above error are as follows:
- Some Weak Hosting
- Due to DDOS, mySQL is overloaded and can't process the data sent and sent back
- Lack of RAM
- Database information of file wp-config.php is entered incorrectly
- Server not responding
- Database does not exist or is corrupted
- Because the connection time to the database expires,…
2. How to fix connection error to WordPress database?
2.1 Fix WordPress database connection errors by checking wp-config . file
File wp-config very important in WordPress. It contains detailed information that helps WordPress to connect to the database in the best way. You should pay attention to the password before and after the change must be the same. To check the file wp-config, you find wp-config and make sure that everything in your wp-config.php file is the same.
define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');
In there:
- WordPress: Name of the database
- Password: Login password
- Admin: Username
2.2 Fix connection error to WordPress database by checking MySQL
You need to check if other websites on the same server have problems before checking if MySQL. If other websites also meet error connecting to WordPress database then surely the MySQL server has a problem. In case you do not have any website on the same host, please visit cPanel => PHPmyadmin => connect. Once the connection is successful, you need to verify if the database has sufficient permissions by creating a new file with the name testconnection.php. Paste the following code into the newly created file:
$link = mysql_connect(‘localhost’, ‘root’, ‘password’);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
echo ‘Connected successfully’;
mysql_close($link);
?
If the connection is successful it means you have enough permissions => go back to the file wp-config => scan for spelling errors
If you can't connect to the database using phpmyadmin => the problem is with the server, not the MySQL server => contact the server provider for support to fix the above error
2.3 Fix connection to WordPress database error with file /wp-admin/
Steps to fix this error occurs with file /wp-admin/ as follows:
Step 1: Check and make sure the above error occurs on both Back-end and Front-end using wp-admin command line as follows:
Error establishing a database connection
Step 2: Once you are sure of the error, to fix it, add the following command to the file wp-config.php
define(‘WP_ALLOW_REPAIR’, TRUE);
Step 3: Go to the browser and type the link below to check if it's done successfully:
https://www.yoursite.com/wp-admin/maint/repair.php
Note: Yoursite: Your website name
Above, BKNS has helped you know 3 more ways to fix it error connecting to WordPress database. If you have a better solution, please share it with BKNS by leaving a comment below the article. Regularly follow other useful articles of BKNS - one of the leading providers of information technology services and network solutions in Vietnam by visiting https://www.bkns.vn/ Please!
My name is Thinh Hanh, currently the CEO of BKNS. I will provide you with information technology services and network solutions in the fastest and most effective way.
Post a Comment
Post a Comment