0

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.

4
  • 2
    There'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. Commented Apr 29, 2016 at 21:58
  • I did not touch the credentials, they are as is :( Commented Apr 29, 2016 at 22:01
  • you might wanna go through this blog post wpbeginner.com/wp-tutorials/… Commented Apr 30, 2016 at 3:08
  • thank you, I'll give it a try Commented Apr 30, 2016 at 16:12

9 Answers 9

14

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 ;-)

Sign up to request clarification or add additional context in comments.

1 Comment

When testing database connection within a plugin (such as Duplicator Pro), enter 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).
3

For me, the fix was this in the wp-config.php file:

/** MySQL hostname */ define('DB_HOST', '127.0.0.1:3307');

The port 3307 was the default when I installed Bitnami Wamp.

Comments

2

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

2

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. enter image description here

  1. Than you should do the same for Mysql my.ini, there are again three places where you should change port number to 3306.

  2. 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

1

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.

Comments

1

"Can't select database" or "Error establishing a database connection" error occurs sometimes due to MySql database port conflict.

Resolution for this issue is changing the MySql port number or in the Wordpress installion you should type 'localhost:3308' in the Database Host field.

Comments

1

If you are installing Wordpress, ensure to get the port which MySQL works, then, in the install settings screen for wordpress, write LOCALHOST:... And that's all folks!.

Comments

0

Error establishing a database connection is a message that comes when the data in the wp-config file is not matching with the actual database credentials. Try to figure out the Database name, user and password is all correct.

Comments

0

was facing the same problem in wamp. I fixed it by changing the host to localhost:3308

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.