This article of wpexpelor is about one of the most common WordPress errors! Many people search: “Error establishing a database connection WordPress localhost wamp” to get rid of it! Simply, this error shows that WordPress cannot connect to the database. It can have many different reasons. But mainly, the error occurs because of wrong database information or database server problems. Here, we will teach you 4 different ways to solve the problem! Great! Stay with us.
Edit wordpress database information.
Have you recently moved your wordpress website to another hosting service? We have found the problem! To solve the problem, check “wp-config.php” for correct information.
Open the file manager from your website’s hosting panel. Find the “wp-config.php” file and look for this code within the file:
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define('DB_HOST', 'localhost');
These four lines of code define how the database is connected to WordPress. You must put the written information in the quotation, and if you don’t know the answer, open the “phpMyAdmin” section to find it. Any way! When you finish editing, save the file and refresh the website. If the problem wasn’t solved keep reading!
WordPress database repair and optimization
Sometimes, we get “Error establishing a database connection WordPress localhost wamp” because of general database problems, or some tables may have been omitted! To solve the problem, you should repair and optimize your wordpress website. Open host control panel. And then, go to the “phpMyAdmin” section to find your database.
Select all the tables and click “Repair table” from the drop-down part. This may solve your problem. After repairing the database, it is now time to optimize it. Again, select all tables and select “Optimize table.” This helps to optimize the database and clears the useless space.
When you finish, refresh the website to see the results.
Changing the database address from localhost to host IP
Your database server may be located on another host, and localhost is unsuitable. In this case, you must change the database address from localhost to the host’s IP.
Open your hosting panel and look for the “wp-config.php” file from the file management section. In this file, find the following line:
/** MySQL hostname */
define('DB_HOST', 'localhost');
This line shows the database server address. You need to replace localhost with your host IP. If you don’t know your host IP, you can ask your host’s support or check it through phpMyAdmin.
Refresh your site page again.
“Error establishing a database connection” is solved? If not, the problem is not yours! Continue reading!
Contact hosting support
If none of the solutions for database establishing error that we Offred didn’t work, you have to contact your hosting support. Your database server may have some problems! Report the problem and ask your website hosting support to solve it!
I hope this article of wpexpelor was useful for you. Comment questions!