The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Intermittent problem establishing database connection on localhost (2 posts)

  1. thesheep
    Posted 6 years ago #

    I have a strange problem when using my local development machine setup. It is set up using WordPress with PHP5 and MySQL on OSX Leopard.

    What happens is that I frequently get an "error establishing database connection" error page when trying to publish a post, or perform some other operation. I know all the settings in the wp-config.php file are correct. If I refresh the page it usually works OK the second time, and the post publishes correctly.

    It's almost as if the database doesn't respond the first time, or something?

    Could this be some kind of time-out issue in my local MySQL setup? Anyone else come across this problem?


  2. prashantrshah
    Posted 6 years ago #

    That message, "Error establishing a database connection", usually means one of two things:

    1. Database server is down (not operating)

    2. You have wrong information in your wp-config.php--either the DB_HOST, DB_USER, DB_PASSWORD, or DB_NAME is incorrect.

    For the case which is mentioned above, first option won't apply as it is connecting to the server when refreshed each time after inserting, updating or sometimes connecting to the website. Sometimes it connects and sometimes after refreshing it connects.

    And after refreshing it connects it means that information in the wp-config is in working condition. Now for some hosting servers the DB_HOST name makes a difference.

    You can try the following setting vice versa. If you are using localhost then change it to the hostname of your site. And if you are using hostname then change it to the localhost.

    /** MySQL hostname */
    define('DB_HOST', 'localhost');


    /** MySQL hostname */
    define('DB_HOST', 'yoursitename.com');

    Hope this solve your problem

Topic Closed

This topic has been closed to new replies.

About this Topic