I had wordpress running on my localhost wamp server, and then I decided to reinstall it since it got slow, now after reinstalling, I keep recieving this ERROR : Error establishing a database connection.
-
2There's really not enough info here to help solve this issue. Many things could be causing this error from a corrupt database to you just putting in the wrong credentials. You should either edit your post to discuss the things you've tried so far, or perhaps do a little more research on the error itself.NoChinDeluxe– NoChinDeluxe2016-04-29 21:58:22 +00:00Commented Apr 29, 2016 at 21:58
-
I did not touch the credentials, they are as is :(Mehdi Rezzag Hebla– Mehdi Rezzag Hebla2016-04-29 22:01:55 +00:00Commented Apr 29, 2016 at 22:01
-
you might wanna go through this blog post wpbeginner.com/wp-tutorials/…Dhaval Chheda– Dhaval Chheda2016-04-30 03:08:01 +00:00Commented Apr 30, 2016 at 3:08
-
thank you, I'll give it a tryMehdi Rezzag Hebla– Mehdi Rezzag Hebla2016-04-30 16:12:34 +00:00Commented Apr 30, 2016 at 16:12
9 Answers
Watch this video and follow instructions https://www.youtube.com/watch?v=hCXDGA0b4hE
So I followed the advice, it worked...but even though I could login to my SQL database with phpmyadmin and see my database, when running the webpage in localhost, I got error saying Database not found.
Solution... just go to your
wp-config.php
file and edit the MySQL hostname section change the following
define('DB_HOST',localhost)
---- change to ------
define('DB_HOST','127.0.0.1:3307)
where 127.0.0.1 is default for home and the :3307 specifies the new port you have allocated for MySQL. It won't necessarily be 3307.
So whatever port you newly allocated to MySQL this is the one you use 3307, 3308 or anything else allocated.
PLEASURE ;-)
1 Comment
localhost:3308 (or whatever port your WAMP db is running from). I have not yet needed to change my hostname as you had to, but I will try localhost:3308 first, then 127.0.0.1:3308 if that does not work. Thanks for giving me the good idea for my (different, but related) issue with Duplicator (wordpress site duplicator/migration plugin).Look at the wp-config.php file: Make Sure Your Database Name is Correct In this case my database name is 'b2w'
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'b2w');
Make Sure the database username is set to 'root'
/** MySQL database username */
define('DB_USER', 'root');
Make absolutely sure the password is blank ' ' the default entry is usually 'password_here', change this to nothing ' '.
/** MySQL database password */
define('DB_PASSWORD', '');
The rest should remain as is Save and close this file after making the necessary changes and then try again
Comments
Ok, solved this next way. The problem is because WAMP now is containing also MariaDB and by default they set 3306(default Mysql port) to this service, for Mysql they set 3307.
If you want to change it you should
1. Change ports in MariaDb my.ini, there you have to change port in 3 places on for example 3307, it should be everywhere the same number 3306.

Than you should do the same for Mysql my.ini, there are again three places where you should change port number to 3306.
After need to restart services, the most simple way to restart all services by the wamp dropdown option "Restart all services".
Or you can just use another port what system gave to Mysql, probably it is 3307 or 3308.
Comments
I had the same error and it was because I had the wrong credentials. The default database credentials on WAMP Server are user:root, with blank password. This might be tricky, because other platforms (eg MAMP) have different default database credentials (eg user:root, password:root).
Another possible cause is that your database does not exist.
In this case you need to create your database by going to localhost/phpmyadmin/.
Make sure the name of the database you create there is same as the database you put in the wp setup page.
Those are the 2 main causes, other than that maybe the MySQL connection is down, so check that WAMP's MYSQL service is up and running.