local installation - Error establishing a database connection with XAMPP

admin2025-04-20  0

I'm just getting started with Wordpress, and currently using an XAMPP server to try and get a local installation working. The localhost environment is working fine, and I've successfully followed the steps here to create a database and user account for Wordpress using phpMyAdmin.

However, when navigating to localhost/wordpress to begin the Wordpress installation and enter my credentials into the relevant fields, I get the error:

Error establishing a database connection

I also discovered through a fluke that when I enter no password at all in the password field, I get a different, more specific error that claims my credentials are correct:

Can’t select database

We were able to connect to the database server (which means your username and password is okay) but not able to select the hashim_wordpress database.

Are you sure it exists?

Does the user Hashim have permission to use the hashim_wordpress database? On some systems the name of your database is prefixed with your username, so it would be like username_hashim_wordpress. Could that be the problem?

However, this can't be the case as that user account definitely has a password set.

My database name is hashim_wordpress, my user account is Hashim, and my password is definitely correct. phpMyAdmin lists my server as 127.0.0.1, but I've also tried localhost. What could I possibly be doing wrong here?

I'm just getting started with Wordpress, and currently using an XAMPP server to try and get a local installation working. The localhost environment is working fine, and I've successfully followed the steps here to create a database and user account for Wordpress using phpMyAdmin.

However, when navigating to localhost/wordpress to begin the Wordpress installation and enter my credentials into the relevant fields, I get the error:

Error establishing a database connection

I also discovered through a fluke that when I enter no password at all in the password field, I get a different, more specific error that claims my credentials are correct:

Can’t select database

We were able to connect to the database server (which means your username and password is okay) but not able to select the hashim_wordpress database.

Are you sure it exists?

Does the user Hashim have permission to use the hashim_wordpress database? On some systems the name of your database is prefixed with your username, so it would be like username_hashim_wordpress. Could that be the problem?

However, this can't be the case as that user account definitely has a password set.

My database name is hashim_wordpress, my user account is Hashim, and my password is definitely correct. phpMyAdmin lists my server as 127.0.0.1, but I've also tried localhost. What could I possibly be doing wrong here?

Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked May 13, 2019 at 20:33 Hashim AzizHashim Aziz 2977 silver badges19 bronze badges 3
  • By default, Xampp sets up the MySQL username as "root" with no password. Unless you have manually created a MySQL user with your username - which is not the same as your Windows username - try "root" as the username in wp-config.php. – WebElaine Commented May 13, 2019 at 20:58
  • @WebElaine As I already mentioned in the question, I followed the linked steps to create a MySQL database and user account. – Hashim Aziz Commented May 13, 2019 at 21:10
  • Can you post a screenshot of your phpmyadmin window? – Vishwa Commented May 14, 2019 at 4:38
Add a comment  | 

2 Answers 2

Reset to default 0

Try using 127.0.0.1:3306 instead of using localhost.

:3306 is the default port when using PHP7. That should do it.

The issue was the user's Host name field.

From the PHPMyAdmin dashboard, go to User accounts, select Edit privileges for the user that you previously created, and select the Login Information tab.

Here, there'll be a field called Host name with a dropdown menu and a text field:

By default this dropdown is set to Any host, and the host name itself as %.

However, what Wordpress' documentation fails to make mention of is that the % hostname doesn't allow for local development, despite the fact that this is probably the most common way to develop with Wordpress.

This is because % doesn't include localhost or 127.0.0.1, as explained in this Stack Overflow answer.

Resolving the issue

This is now easily solved by creating a new user account with the same permissions as the current one, while changing its host name of localhost. The old, broken user account is deleted for the sake of tidiness.

For the user account in question, change the drop down in the Host name field to Local - this will automatically set the host name to localhost:

In the field below, select delete the old one from the user tables, and click the Go button to push the changes:

After doing this, I was able to navigate to localhost/wordpress and enter my credentials as normal, resulting in a successful local installation of Wordpress.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745080902a283851.html

最新回复(0)