• HashimA

    (@kaosindustries)


    Hey there,

    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 nevigating to localhost/wordpress to enter my credentials into the relevant fields and begin the WordPress installation, 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 because 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?

    Thank you in advance, I’d really appreciate the help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Did you start the MySQL process?
    Were you at localhost/wordpress or localhost/wordpress/wp-admin/install.php ?

    Thread Starter HashimA

    (@kaosindustries)

    Yes, MySQL and Apache are both running.

    Both localhost/wordpress and localhost/wordpress/wp-admin/install.php redirect to localhost/wordpress/wp-admin/setup-config.php, which is the page that I was entering the credentials on.

    • This reply was modified 5 years, 6 months ago by HashimA.

    In phpMyAdmin, did you give the db user the permissions to access the database? That’s what the page is asking you also.

    Does the user Hashim have permission to use the hashim_wordpress database?

    Thread Starter HashimA

    (@kaosindustries)

    Yes, as mentioned in the post, I followed every step of the instructions in the WordPress codex – step 8 deals with granting privileges.

    Create test.php

    <?php
    $mysqli = new mysqli("127.0.0.1", "hashim", "password", "hashim_wordpress", 3306);
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }
    
    echo $mysqli->host_info . "\n";
    $mysqli->close();
    ?>

    https://yourdomain.com/test.php
    Your default port is 3306?
    Now delete test.php

    if this also doesn’t work in the host field select localhost instead of any host .. first you have to delete the user and then recreate it

    Thread Starter HashimA

    (@kaosindustries)

    It’s not entirely clear what I’m meant to do , but if I’ve understood you correctly, here’s what I did:

    – Created a file called test.php in XAMPP/htdocs, with the content above, replacing with my username and password

    – Navigated to localhost/test.php in my browser

    Here’s the output of test.php displayed by the browser:

    Warning: mysqli::__construct(): (HY000/1045): Access denied for user ‘Hashim’@’localhost’ (using password: YES) in B:\Users\Hashim\Desktop\Charity Website\XAMPP\htdocs\test.php on line 2
    Failed to connect to MySQL: (1045) Access denied for user ‘Hashim’@’localhost’ (using password: YES)
    Warning: main(): Couldn’t fetch mysqli in B:\Users\Hashim\Desktop\Charity Website\XAMPP\htdocs\test.php on line 7

    Warning: mysqli::close(): Couldn’t fetch mysqli in B:\Users\Hashim\Desktop\Charity Website\XAMPP\htdocs\test.php on line 8

    Thread Starter HashimA

    (@kaosindustries)

    Success! Thanks a lot autotutorial, your last post was what turned out to be the problem. I needed to change the dropdown in PHPMyAdmin for the user’s “Host name” field (under the Login Information tab) from “Any Host” to “Local”, which automatically changed % to localhost. I looked into why this is, and apparently it’s because % does not include localhost – see this StackOverflow answer.

    The fact that the WordPress Codex doesn’t reflect this, however, considering how common it is to work on WordPress locally, seems to me a huge oversight, and something that should be amended as soon as possible.

    Once again, thanks for your help autotutorial.

    • This reply was modified 5 years, 6 months ago by HashimA.

    any host indicates remote access to any ip while the server is blocked on the local ip. I’m glad you solved it and after reading that a charity site I can claim to have done something good for today ??
    https://mariadb.com/kb/en/library/configuring-mariadb-for-remote-client-access/

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Error establishing a database connection with XAMPP’ is closed to new replies.