• Resolved nelsonov

    (@nelsonov)


    I am going through the setup procedure, but I keep getting “Error establishing a database connection” when I try to runn the “install.php” script. I can connect to the database from the command line with the same information that is in wp-config.php:

    mysql -h localhost -u wordpress wordpress -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 129054 to server version: 4.0.18-Max-log

    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

    mysql>

    I can also run “php install.php” and it talks about going through some steps, so I know that php can access the database from the command line.

    Here are the versions I’m running:
    mysqld -v
    mysqld Ver 4.0.18-standard for pc-linux on i686 (Official MySQL RPM)

    php -v
    PHP 4.3.2 (cgi), Copyright (c) 1997-2003 The PHP Group
    Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

    I am using php with squirrelmail just fine and mysql is working with postfix. What I’m struggling with is finding out exactly where the connection is failing. I see the connection attempts in query.log for both sucessful and purposefuly unsuccessful (ie mistyped password) when I connect from the command line. I also see a great deal of output in query.log when I run “php install.php” from the command line, so again, I know that a connection is being established that way. However, I don’t see any attempts at connections (failed or otherwise) in query.log when I run install.php from the web. Is there some way to turn on some sort of logging within php or wordpress to see why exactly the connection attempt is dying?

    Here’s my wp-config.php with the password blanked out:

    <?php
    // ** MySQL settings ** //
    define(‘DB_NAME’, ‘wordpress’); // The name of the database
    define(‘DB_USER’, ‘wordpress’); // Your MySQL username
    define(‘DB_PASSWORD’, ‘######’); // …and password
    define(‘DB_HOST’, ‘localhost’); // 99% chance you won’t need to change this value

    // You can have multiple installations in one database if you give each a unique prefix
    $table_prefix = ‘wp_’; // Only numbers, letters, and underscores please!

    // Change this to localize WordPress. A corresponding MO file for the
    // chosen language must be installed to wp-includes/languages.
    // For example, install de.mo to wp-includes/languages and set WPLANG to ‘de’
    // to enable German language support.
    define (‘WPLANG’, ”);

    /* That’s all, stop editing! Happy blogging. */

    define(‘ABSPATH’, dirname(__FILE__).’/’);
    require_once(ABSPATH.’wp-settings.php’);

Viewing 1 replies (of 1 total)
  • Thread Starter nelsonov

    (@nelsonov)

    I finally managed to answer my own question. The short answer is that for some reason PHP was logging in with the full domain name of the web server rather than as ‘localhost’, so I needed a user like this:

    ‘wordpress’@’fqdn.myserver.com’
    instead of
    ‘wordpress’@’localhost’

    I discovered this by tampering with my wp-db.php in wp-includes. I’m not a PHP programmer, so I’m sure there’s a better way to do this, but this worked for me. All the changes are near the top of the script (BTW, this is WordPress 2.0.1), so I’ll just show the pertinent part:

    class wpdb {

    var $show_errors = true;
    var $num_queries = 0;
    var $last_query;
    var $col_info;
    var $queries;

    // Our tables
    var $posts;
    var $users;
    var $categories;
    var $post2cat;
    var $comments;
    var $links;
    var $linkcategories;
    var $options;
    var $optiontypes;
    var $optionvalues;
    var $optiongroups;
    var $optiongroup_options;
    var $postmeta;
    var $my_errstr;

    // ==================================================================
    // DB Constructor – connects to the server and selects a database

    function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
    $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
    if (!$this->dbh) {
    $my_errstr=mysql_error();
    $this->bail(“
    <h1>Error establishing a database connection</h1>
    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
    $dbhost. 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?

    If you’re unsure what these terms mean you should probably contact your host.
    If you still need help you can always visit the <a href=’https://www.ads-software.com/s
    upport/’>WordPress Support Forums.
    Error: $my_errstr;
    “);

    The parts I added are the three lines with “$my_errstr”. This printed out the exact database error. This might be something that the WordPress developers could consider implementing (with better coding) in future releases. It could save people many hours of head scratching.

Viewing 1 replies (of 1 total)
  • The topic ‘Error Establish a databese connection’ is closed to new replies.