• Resolved mwbelt

    (@mwbelt)


    This is far and away not my first WP install, but it’s the first time I’ve seen this and I can’t find a workaround.

    I have two servers, which for argument’s sake are web1 and db2. Let’s say their IPs are 11.11.11.11 and 22.22.22.22 respectively.

    I’ve created the WP user and database on db2 along with appropriate privileges, flushed the table, etc. etc. If I am SSH’d into web1, I can easily connect as that user to the database on db2. To wit:
    mysql –user=theusername –password=thepassword –host=22.22.22.22 databasename

    This works fine. I can get in, create and drop tables, etc. HOWEVER, putting those EXACT same credentials and host info into the installation dialog (or directly into wp-config.php) results in the old familiar:

    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 22.22.22.22. 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?
    If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

    Nothing works. I have tried any workaround I can think of, and I am now banging my head against my desk.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator t-p

    (@t-p)

    “Error establishing a database connection” means that there is a problem with the connection to your database:
    – a problem with the credentials stored in the wp-config.php file not matching what mysql expects.
    – Try reviewing the following codex for some guidance: http://codex.wordpress.org/Common_WordPress_Errors#Error_Establishing_Database_Connection
    – Also review this tutorial: http://www.wpbeginner.com/wp-tutorials/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/

    Are either of your servers running a firewall such as iptables?

    If so, you may want to try whitelisting each server to accept incoming and outgoing connections:

    SSH Into 11.111.11.11:

    # iptables -A INPUT -s 22.22.22.22 -j ACCEPT

    # iptables -A OUTPUT -s 22.22.22.22 -j ACCEPT

    SSH Into 22.22.22.22:

    # iptables -A INPUT -s 11.111.11.11 -j ACCEPT

    # iptables -A OUTPUT -s 11.111.11.11 -j ACCEPT

    For the heck of it, you may also wish to check and make sure your wp-config.php file is using the correct table prefix as this can sometimes get overlooked ;).

    Good luck!

    Thread Starter mwbelt

    (@mwbelt)

    Thanks for the good suggestions, all. And yes, I’d tried the iptables route to no avail.

    Turns out the hosting company (who knew we’d be using separate web and db servers) decided to go ahead and set up SELinux with everything on complete lockdown, thus preventing httpd from doing any networking.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Error establish connection even though mysql command line works’ is closed to new replies.