WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Error establishing database connection (8 posts)

  1. markpea
    Member
    Posted 3 years ago #

    I have made dozens of installations of WordPress on my FreeBSD server with no problems until now. I set up the database from the command line:

    mysql> CREATE DATABASE quake DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    mysql> GRANT ALL PRIVILEGES ON quake.* TO quakeuser@localhost IDENTIFIED BY '******';

    And I enter the parameters into the wp-config.php:

    define('DB_NAME', 'quake');
    define('DB_USER', 'quakeuser');
    define('DB_PASSWORD', '********');
    define('DB_HOST', 'localhost');
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', 'utf8_unicode_ci');

    I run the readme.html and go to wp-admin/install.php
    I enter the site name, admin username and password. Checking with phpmyadmin I see that 11 tables are created.
    When I click [Login] I get the dreaded message:
    "Error establishing database connection"
    (where does this come from by the way?)
    How can this be since install.php already accessed the database in order to create the initial tables. I thought it might be a bug so I checked out the latest trunk from svn but got the same error. I'm utterly flummoxed!
    As I say, I've done dozens of installs and this is the first that's tripped me up. Any ideas?

  2. Tara
    Member
    Posted 3 years ago #

    -First, try contacting the hosting provider if the database server is online / if they have any other problem at their end, or they made any changes to your account, or if there are any limitations/restrictions, etc .

    - double check your wp-config.php file settings for the database name, database username and database password. This is where most errors occur.

    -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, and you may need to contact your hosting provider.

    Ask your hosting provider if the database server is online / if they have any other problem at their end, or they made any changes to your account, or if there are any limitations/restrictions, etc . Also check with them if you need to upgrade the hosting account in order to install and run your verson of the WordPress.

    There are also many threads on this topic on these forums: http://wordpress.org/search/Error+establishing+a+database+connection?forums=1

  3. markpea
    Member
    Posted 3 years ago #

    -First, try contacting the hosting provider if the database server is online / if they have any other problem at their end, or they made any changes to your account, or if there are any limitations/restrictions, etc .

    The server is in the machine room next door. I have other WP databases currently running with older versions of WP (v3.0).

    - double check your wp-config.php file settings for the database name, database username and database password. This is where most errors occur.

    I've gone over these settings with a fine tooth comb. What I don't understand is that admin/wp-install.php creates and populates 11 tables in the database before returning to wp-login.php. So the system must have accessed the database using the info in wp-config in order to do this, don't you agree?

    -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.

    I don't understand this either. All the other WordPress and Moodle installs I have done use 'localhost' successfully. Why would I need to change it now? But I did try '127.0.0.1' without success (same error message). I do have sole access to this server (it's my sandbox) so there's no other user account that could screw things up.

    -Check you have actually created a database with the same database name as is in your wp-config.php file.

    Yes, I checked with phpmyadmin and 11 tables were created :
    mysql> show tables;
    '+-----------------------+
    | Tables_in_quake |
    +-----------------------+
    | wp_commentmeta |
    | wp_comments |
    | wp_links |
    | wp_options |
    | wp_postmeta |
    | wp_posts |
    | wp_term_relationships |
    | wp_term_taxonomy |
    | wp_terms |
    | wp_usermeta |
    | wp_users |
    +-----------------------+
    '

    -Last, but not least, if all that information is correct your database probably has a problem with it, and you may need to contact your hosting provider.

    Ask your hosting provider if the database server is online / if they have any other problem at their end, or they made any changes to your account, or if there are any limitations/restrictions, etc . Also check with them if you need to upgrade the hosting account in order to install and run your verson of the WordPress.

    Again, I have sudo access to this server so the hosting provider is me. It already runs WP3.0 with no problems, it's just this latest 3.12 which is giving me gyp.
    Here's another thing. The following code:

    <?php
    $db = @mysql_connect('localhost', 'quakeuser', '*******');
    if (!$db) echo "connection failed";
    else echo "connection succeeded";
    ?>

    located in the same directory as wp-login.php when run from Firefox outputs 'connection succeeded'
    I really appreciate your taking the time to help me out here. This is driving me bats!

  4. hulong2010
    Member
    Posted 3 years ago #

    are you sure the DB_HOST is localhost?

  5. markpea
    Member
    Posted 3 years ago #

    OK. I have sussed the problem and the database connection is established properly. Initially I knew that I wanted 'network' and 'multisite' options and so I added them to the wp-config.php before firing up WP. Wrong thing to do! After carefully consulting the online documentation and having started up a new installation from scratch I fired up WP and was able to login. Then I added the line define('WP_ALLOW_MULTISITE', true); to the wp-config.php on the fly while still logged in. I reloaded and hey presto the 'Network' option appeared under the Tools menu. I configured the network for multisite True and subdomain install false and then got the instructions to create a Network of WordPress sites (the details of which were exactly the same as I had used before!). I added the requisite lines to wp-config.php and recreated the .htaccess. Now when I logged out and then back in again the site came up correctly and I can carry on.
    Conclusion
    I thought I could cut a corner and speed the installation by adding the site definition stuff before the initial login.

    define( 'MULTISITE', true );
    define( 'SUBDOMAIN_INSTALL', false );
    $base = '/';
    define( 'DOMAIN_CURRENT_SITE', 'quake.sergius.earlham.edu' );
    define( 'PATH_CURRENT_SITE', '/' );
    define( 'SITE_ID_CURRENT_SITE', 1 );
    define( 'BLOG_ID_CURRENT_SITE', 1 );

    However, this just doesn't work! You have to startup your WP install in single user mode and then add the multisite and network capability. That this is somewhat counter intuitive is shown by my assuming that config statements are state neutral when in fact it seems that this is not necessarily the case.
    Anyway,. all is hunky dory now and thanks for all the helpful comments.
    Mark

  6. Tara
    Member
    Posted 3 years ago #

    Excellent! :-)

  7. aliva08
    Member
    Posted 3 years ago #

    Before the initial login.

    define( 'MULTISITE', true );
    define( 'SUBDOMAIN_INSTALL', false );
    $base = '/';
    define( 'DOMAIN_CURRENT_SITE', 'quake.sergius.earlham.edu' );
    define( 'PATH_CURRENT_SITE', '/' );
    define( 'SITE_ID_CURRENT_SITE', 1 );
    define( 'BLOG_ID_CURRENT_SITE', 1 );

    3C Sports Village

  8. aliva08
    Member
    Posted 2 years ago #

    DB_HOST is the localhost
    Jaypee Greens Garden Isles

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.