• I installed WordPress on XAMPP. I get an error: “Error establishing a database connection”. As far as I know, “The ‘Error establishing a database connection’ issue can be caused by incorrect database information in your WordPress settings, corrupt database, or an irresponsive database server.” (https://www.wpbeginner.com/wp-tutorials/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/)

    In wp-config.php I have:
    define(‘DB_NAME’, ‘wordpress’);
    /** MySQL database username */
    define(‘DB_USER’, ‘root’);
    /** MySQL database password */
    define(‘DB_PASSWORD’, ”);
    /** MySQL hostname */
    define(‘DB_HOST’, ‘localhost’);

    PhpMyAdmin starts up without any problem. The database is there and is called ‘wordpress’. config.inc.php file contains the following data:
    $cfg[‘Servers’][$i][‘user’] = ‘root’;
    $cfg[‘Servers’][$i][‘password’] = ”;
    $cfg[‘Servers’][$i][‘host’] = ‘127.0.0.1’;

    So the database login credentials are correct, right? If yes, what else should I check?

    • This topic was modified 4 years, 4 months ago by Yui. Reason: moved to "localhost installs"
Viewing 5 replies - 1 through 5 (of 5 total)
  • Arno

    (@arnovanessen)

    Hi there,

    Looking at the wp-config.php snippet you provided, it looks like you didn’t use a password or removed it to post it here. If you didn’t you a password please try the following. After define(‘DB_PASSWORD’, there is a " instead of ''. Please change this.

    IF you removed the password form the snippet, please double check the password in the wp-config.php. This may sound redundant, but I have seen it happen before that a typo slipped in.

    I hope this helps.

    Regards,
    Arno

    Dion

    (@diondesigns)

    If this is a Windows-based system, you should never use localhost for the MySQL hostname in a PHP application. Your snippet from phpMyAdmin provides the answer: use 127.0.0.1 for the hostname.

    Also make sure your Windows firewall isn’t blocking port 3306 because it will be used by MySQL.

    Thread Starter reti

    (@reti)

    Thanks guys! @arno I don’t use a password, there is definitely ”. I don’t know why it was copied like that. @dion I changed the word ‘localhost’ to 127.0.0.1 and that didn’t help. The database is on port 3307, not 3306:
    $cfg[‘Servers’][$i][‘port’] = 3307;

    Dion

    (@diondesigns)

    If that’s the case, then you will need this for the hostname:

    define(‘DB_HOST’, ‘127.0.0.1:3307’);

    Your firewall should be fine since phpMyAdmin is successfully accessing MySQL on port 3307.

    Thread Starter reti

    (@reti)

    Thank you guys. I am very grateful. @dion, that’s what this was about.

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