• I have an installation of WP3.8 hosted online that I have made a copy of and installed locally, to continue working on it offline and to be uploaded and update the online version once completed.

    Upon accessing the site I get the infamous: Error establishing a database connection.

    I have tried the following:
    Checked the parameters in wp-config.php – These correct.
    Modified the urls “siteurl” and “home” fields in the wp_options table in the WP database. – These are correct.
    Modified .htaccess in the localhost/wordpress folder and modified the RewriteBase /wordpress statement.
    Checked the above several times for possible spelling errors.
    Checked the connection to the database is working by using a testconnection.php script. The script works and reports successful connection. This also confirms that the dbhost, dbuser, and dbpassword are correct.
    Checked the MySQL server is working – confirmed
    Checked MySQL error log – no errors
    Checked the Appache server is working – confirmed
    Checked Appache error log – no errors
    Checked PHP error log – no errors
    Checked the database using phpMyAdmin – confirmed and Repaired
    Tried to repair the database with the repair.php script in localhost/wordpress/wp-admin/maint – the script reports the database connection error
    Tried to access the localhost/wordpress/wp-admin – it reports the following:

    Error establishing a database connection
    If your site does not display, please contact the owner of this network. If you are the owner of this network please check that MySQL is running properly and all tables are error free.

    Could not find site localhost/wordpress. Searched for table wp_blogs in database wpdb. Is that right?

    What do I do now? Read the bug report page. Some of the guidelines there may help you figure out what went wrong. If you’re still stuck with this message, then check that your database contains the following tables:

    wp_users
    wp_usermeta
    wp_blogs
    wp_signups
    wp_site
    wp_sitemeta
    wp_registration_log
    wp_blog_versions

    Verified if wp_blog exists – confirmed.
    Checked the bug report page Other lessor known issues:
    Checked root (MySQL user) has all privileges to the wp database – confirmed

    I would greatly appreciate any assistance in resolving this. Thank you in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • What are you using for a local server? XAMPP, MAMP (Mac), etc.

    This is the way I usually do this:

    Live site:
    – export the database and download the .sql file
    – ZIP the entire contents of the site and download

    Local site:
    – create new, empty database
    – import the exported .sql file into it
    – edit the siteurl and home fields in wp_options table with the local site URL
    – create a new folder in the root of the local server and unZIP the site there
    – edit wp-config.php in the local site for the local database credentials
    – run this script to change the URLs of links, media, etc. to the local URL:

    https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

    Note: this scrip handles URLs that are stored in the database as serialized strings; the Velvet Blues Update URLs does not handle these.

    – log in to local site, install and run this plugin:

    https://www.ads-software.com/plugins/velvet-blues-update-urls/`

    Note: I have found occasions where the search and replace script did not catch all items; running this one completed the task.

    That’s it. Sounds like a lot but generally takes me about 5 minutes.

    One more thing … go to Permalinks and just re-save.

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