• Dear Forum

    probably a common one. i have uploaded my WordPress to my site, created an SQL, put the SQL details into wp-config.php and i get error:

    Error establishing a database connection

    i understand that this is because the wp-config file cant login to the SQP DB. i have entered the details from my hosting to the file. where my hosting uses ‘user_DBname’, i have entered ‘user_DBname’ and not ‘DBname’… is that correct including the user prefix from hosting?

    i have changed the 3 attributes asked to change:

    NAME
    USER
    PASSWORD

    i havent changed HOST as its sat at ‘localhost’. i use a hosting with cPanel so i think thats correct…

    have i missed something?

    i edited the wp-config file myself as it talks about it setting automatically but i dont know where it does that???

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

    (@t-p)

    Error connecting to your database:

    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.
    – There are also many threads on this topic on these forums: https://www.ads-software.com/search/Error+establishing+a+database+connection?forums=1

    Thread Starter andihawes

    (@andihawes)

    i have double checked my settings in that file, even deleted the DB i created and made another. it still doesn’t find it??!?

    Did you already tried to insert like this:

    define('DB_HOST', 'your_host_ip:8889');
    instead of localhost

    Or could be a problem connection to your mysql server.
    Create a new file like conn.php and write this:

    <?php
    $link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db", "my_port");
    
    if (!$link) {
        echo "Error: Unable to connect to MySQL." . PHP_EOL;
        echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
        echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
        exit;
    }
    
    echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
    echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
    
    mysqli_close($link);
    ?>

    – If connects successfully verify the user permissions and verify again your wp-config there is something wrong
    – if you can’t connect, well is your server and probably you have to contact your host

    Common error too, if luis solution possible solution doesn’t work,

    Most Web hosts use “localhost” as database server:

    wp-config.php file:

    define('DB_HOST', 'localhost');

    wp-config.php is probably the single most important file in your entire WordPress installation. This is where you specify the details for WordPress to connect your database. If you changed your root password, or the database user password, then you will need to change this file as well. First thing you should always check is if everything in your wp-config.php file is the same.
    1
    define(‘DB_NAME’, ‘database-name’);
    2
    define(‘DB_USER’, ‘database-username’);
    3
    define(‘DB_PASSWORD’, ‘database-password’);
    4
    define(‘DB_HOST’, ‘localhost’);

    Remember your DB_Host value might not always be localhost. Depending on the host, it will be different. For popular hosts like HostGator, BlueHost, Site5, it is localhost. You can find other host values here.

    Some folks suggested that they fixed their problem by replacing localhost with the IP. It is common to see this sort of issue when running WordPress on a local server environment. For example on MAMP, the DB_Host value when changed to the IP may seem to work.
    1
    define(‘DB_HOST’, ‘127.0.0.1:8889’);

    +1 to all chrisan said, some hosts use specific database server that is not in the “direct” grasp of web servers cluster, hence using ip of name for it:

    be it an ip with port:

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

    or a “half” local address, compared to web server:

    define(‘DB_HOST’, ‘mysql-cluster-12’);

    Also, I will retaliate saying testing WordPress on your own computer (MAMP,WAMP, whatsoever) is in general, a very bad experience of WordPress. Local firewalls, port conflicts and so often squeeze the best of it.

    There are host for a few bucks that really show it in a Linux environment – or shared with just a button to push (and you can test on it, just using FTP to transfer files and Phpmyadmin – in case you need to change stuff in database)..

    so you solved it yet ?

    +1, is it solved now?

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