• Resolved CalleZorro

    (@callezorro)


    Hello,

    I have uploaded the WP 4.1.1 files to my website (where I am running MySql 5.5).

    I have uploaded a wp-admin/wp-config.php file that has the correct, database name, user name, password, and hostname.

    But, when I run mywebsite.com/wp-admin/wp-config.php, I get the following error:

    “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 ChangedForPrivacy. 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?”

    I double-checked everything in my wp-config.php file that is on my server and it is all correct.

    So, I created the following PHP file to triple-check myself:

    <?php
    $hostname = "ChangedForPrivacy";
    $username = "ChangedForPrivacy";
    $dbname = "ChangedForPrivacy";
    $password = "ChangedForPrivacy";
    
    mysql_connect($hostname, $username, $password) OR DIE ("Unable to
    connect to database! Please try again later.");
    
    echo "Connected";
    ?>

    When I run this PHP file, it definitely tells me it connected.

    I would greatly appreciate any help.

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

    (@t-p)

    In nutshell, you’re getting this error because WP is unable to establish a database connection. Reason why WP is unable to establish a database connection can vary. It could be that your database login credentials are wrong or have been changed. It could be that your database server is unresponsive. It could be that your database has been corrupted. Majority of the times this error happens because of some sort of server error. Also, there could be other factors as well. To troubleshooting this problem:
    – double check your wp-config.php file settings for the database name, database username and database password, and the host name (e.g., “localhost” Vs. something else). This is where most errors occur.
    – Then make sure wp-config.php is in right location.
    – Then check that you don’t need to change the database host from “localhost” to something else. You can get that info from your hosting provider.
    – Check you have actually created a database with the same database name as is in your wp-config.php file.
    – Last, but not least, if all that information is correct your database probably has a problem with it. Contact your hosting provider if the database server is offline (if the problem suddenly happened), or if they have any other problem at their end, or they made any changes to your account, or if there are any limitations/restrictions, or if the hosting package is set to Windows and not Linux, etc.
    – If the error is intermittent then it’s your server. What’s happening is that the web server and/or the database server are gettign overloaded and the connection is droping out or is refused for a short time. That gives you the database error as the website can’t connect to the database. To fix this, you’ll need to talk to your hosting company as they are the only ones that can do anything about hardware issues like this.
    – There are also many threads on this topic on these forums: http://wordpress.org/search/Error+establishing+a+database+connection?forums=1

    Thread Starter CalleZorro

    (@callezorro)

    I’ll provide more information in the event it is useful…

    I downloaded and unzipped the WP 4.1.1 files to my computer.

    I then uploaded and setup/configured WP 4.1.1 on InitiateIntimacy.com with no problems or issues.

    In setting up the InitiateIntimacy.com instance, I copied wp-config-sample.php to wp-config.php and changed the database name, username, password, and host to match my specific credentials.

    I also set $table_prefix = ‘wp_InitiateIntimacy’;

    I then ran wp-admin/install.php and everything worked just fine … and still works just fine.

    Next…

    I uploaded the WP 4.1.1 files to MarriedAndHappy.com

    I again copied wp-config-sample.php to wp-config.php and changed the database name, username, password, and host to match my specific credentials.

    And, I set $table_prefix = ‘wp_MarriedAndHappy’;

    So, to be clear, both instances (InitiateIntimacy.com and MarriedAndHappy.com) are pointing to the same database with the same credentials … and the $table_prefix variable in each wp-config.php file is set uniquely…

    But, when I try to run http://www.marriedandhappy.com/wp-admin/install.php I get “Error establishing a database connection”

    BOTH instances are pointing to the same database … the InitiateIntimacy.com site works fine … the MarriedAndHappy.com instance won’t connect.

    ???

    Clayton James

    (@claytonjames)

    BOTH instances are pointing to the same database … the InitiateIntimacy.com site works fine … the MarriedAndHappy.com instance won’t connect…
    I double-checked everything in my wp-config.php file that is on my server and it is all correct.

    Still, the simplest, lowest, common denominator at this point would suggest a syntax, info, or typo in the wp-config.php file for marriedandhappy.com. Review the entries for missing or errant punctuation and case and see if you can spot something simple like a missing/incorrect character. It’s especially easy to miss a single quotation mark somewhere during the editing process.

    Thread Starter CalleZorro

    (@callezorro)

    Well, Tara named it…

    My problem was that I was putting wp-config.php in the wp-admin directory when it actually needs to be in the root directory.

    In my inexperience with WP, I got criss-crossed in my mind as to where the file was supposed to be.

    A big thank you to everyone who took the time to read and reply.

    Moderator t-p

    (@t-p)

    You are welcome 🙂

    FYI, you can place the wp-config.php:

    – in the root of WP installation
    – or, you can move the wp-config.php file to the directory above your WordPress install. More here http://codex.wordpress.org/Hardening_WordPress#Securing_wp-config.php

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Error establishing a database connection’ is closed to new replies.