• First, I am not a newbie and this is not the usual first time user error.

    I try to run latest WordPress in a regular Docker container tutum/lamp and get this error message during installation – with correct database, user, pass:

    Error establishing a database connection
    This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

    Why do I know the access data is correct? When I enter a WRONG database, I get this error message during installation:

    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 xwordpress database.

    So the first error message is just a plain lie, it can connect, it has some other issues. It’s not “Error establishing a database connection”.

    I checked the user rights on the MySQL user and they seem to be okay:

    SHOW GRANTS FOR CURRENT_USER;
    GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY PASSWORD 'a1b2c3' WITH GRANT OPTION

    So what am I doing wrong? Why is WordPress behaving this way?

    FEATURE REQUESTS:
    1. Show a meaningful error message when something goes wrong with the database
    2. Have a “[ ] Create database” checkbox during the installation process

Viewing 9 replies - 1 through 9 (of 9 total)
  • … the username and password information in your wp-config.php is incorrect

    (Emphasis mine)

    Thread Starter bluepuma

    (@bluepuma)

    No.

    DB_NAME – INCORRECT
    DB_USER – correct
    DB_PASSWORD – correct
    DB_HOST – 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 xwordpress database.

    DB_NAME – correct
    DB_USER – correct
    DB_PASSWORD – correct
    DB_HOST – correct

    => Error establishing a database connection

    This does not make sense.

    I have already proven, that DB_USER, DB_PASSWORD and DB_HOST are correct, because it can tell me that it can’t select the database. So why would it tell me it can’t connect to database if the database name is the only thing that changes from incorrect to correct?

    Did you read the full message?

    Thread Starter bluepuma

    (@bluepuma)

    Did you read the full message?

    DB_NAME – INCORRECT
    DB_USER – correct
    DB_PASSWORD – correct
    DB_HOST – correct

    results in

    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 xwordpress database.
    
    - Are you sure it exists?
    - Does the user admin have permission to use the xwordpress database?
    - On some systems the name of your database is prefixed with your username, so it would be like username_xwordpress. Could that be the problem?

    => That is fine, I can log in, but the database name is incorrect.

    Now I only change the DB_NAME in wp-config.php to be correct.

    DB_NAME – correct
    DB_USER – correct
    DB_PASSWORD – correct
    DB_HOST – correct

    results in

    Error establishing a database connection
    This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.
    
    - Are you sure you have the correct username and password?
    - Are you sure that you have typed the correct hostname?
    - Are you sure that the database server is running?

    => That is wrong, because I already know from previous test, that username, password and hostname are correct and the database server is running. Let me quote again: “We were able to connect to the database server (which means your username and password is okay)”

    Has anyone come up with a solution to the database connection issue? I have reinstalled MAMP Pro and installed about 4 times now, tried 3 different versions of Worpress and still get the same message I am 100% sure that the information being input is correct but I’m getting nowhere…

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    When that message shows up it is always a problem with the credentials stored in the wp-config.php file not matching what mysql expects. If your credentials are not correct or the access was not setup up correctly then that will happen.

    Per the forum welcome please post your own topic and someone can assist you with your specific problem.

    Hello,
    I had this problem earlier as well and after some tweaking I found the thing that caused the problem here. It might be helpful for you:

    In the WP database there might be multiple wp_X_options tables (X being a number, for each different sub-site). All of these need to have their “home” and “siteurl” options set to the same one that the wp_options has as well as the site_blog.
    Example of OLD config:`
    wp_core database

    Table: wp_2_options
    siteurl = https://site.com/help
    home = https://site.com/help
    Table: wp_options
    siteurl = https://site.com
    home = https://site.com
    Table: wp_blogs
    blog_id = 2, site_id = 1
    domain = https:/site.com`
    After changing all of the “https:/site.com” to my actual site (this, for me, is the same as what the “DOMAIN_CURRENT_SITE” is set to in wp-config.php) it finally worked.

    Just add the port number after localhost, like: localhost:8889. It worked for me ??

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