• I’m getting the above on a WP install, and wp-admin invites me to repair some tables.
    mysqlcheck finds no issues with tables, and I can connect fine using the mysql prompt.

    I’ve put a test script in the documentroot of the wp site:

    <?PHP
    $db = @mysql_connect('mysql', '<username>', '<password>');
    if (!$db) echo ":(";
    else echo ":)";

    And when I run that I get a happy face; the problem is somewhere in WordPress’ connection.

    Is there any mechanism for retrieving more detailled information from WordPress here? I can’t find mention of any, and would assume it to be fairly obvious in any case.

    I’ve tried resetting the password with OLD_PASSWORD(), and every hostname I can think of that points at the db server; each of them work on the cli, in my php script, and not in wordpress.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Double check the db host name in wp-config.php.

    Thread Starter BigRedS

    (@bigreds)

    I’ve checked it a few times, but just to be sure I’ve edited the test script so;

    <?PHP
    include("wp-config.php");
    $db = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if (!$db) echo ":(";
    else echo ":)";

    and if I comment out the wp-settings.php call at the bottom of wp-config.php, the connection still works.

    The cause of the problem is somewhere other than my db credentials.

    Try re-uploading all files & folders – except the wp-content folder – from a fresh download of WordPress.

    Thread Starter BigRedS

    (@bigreds)

    I’ve just tried that to no avail.

    Is there not some way to get some diagnostic information out of WP as to what’s going on? Error strings from mysql or something?

    Thread Starter BigRedS

    (@bigreds)

    After way more digging around in the code than should be necessary, I’ve pinned it down to a missing wp_options table.

    Is there some reason WP doesn’t like to say what’s wrong?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Give what’s in the WP_options table, I think it can’t tell you… Thats the table that has the basic connectivity info, so if it’s gone, it just can’t connect.

    Thread Starter BigRedS

    (@bigreds)

    Sure it can. When functions.php does this:

    foreach ($wpdb->tables as $table) {
    // If one of the WP tables exist, then we are in an insane state.
    if ( in_array($wpdb->prefix . $table, $tables) ) {
    // If visiting repair.php, return true and let it take over.
        if ( defined('WP_REPAIRING') )
        return true;
        // Die with a DB error.
        $wpdb->error = __('One or more database tab[...]
        dead_db();

    It could say *which* tables are missing/broken. It could even write it to a file, if you don’t want to tell the world that you’re missing a table. Or put http auth or something in.

    Perhaps more pertinently, all the docs suggest that the only tim you get that message it’s because your db options in wp-config.php are incorrect; this is patently untrue.
    Surely missing db tables are a completely different problem to an inability to connect to a database?

    If tables weren’t created, that suggests that WP couldn’t access the db to create the tables. I suppose there could have been an temporary problem with the MySql server during the install process. Do you have access to the server’s error logs? They might be helpful.

    Otherwise, you could try dropping all table and re-running the install.

    Thread Starter BigRedS

    (@bigreds)

    No, the tables had been created, but somehow disappeared. I know nothing of the history of this wp install, though, I was just asked to have a look when it stopped working. I don’t know how the table disappeared, but the point really is that WP detected that the table had disappeared, but still decided to blame a bad connection to the database.

    Thinking about it, putting this in ‘Installation’ was probably not the best idea I’ve ever had 🙂 I’m sure I was aiming for somewhere else…

    Nothing much of interest was written to the error logs, either. But neither Apache nor MySQL had any errors themselves – it was WP that had the error, it just misreported it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘"Error establishing a database connection" any way of getting more info?’ is closed to new replies.