• I set up a new server with its using Centos 6.3 running apache httpd and mysql as the database. All are on the same box with the same IP address. I have mysql accounts generated for wordpress with host names of localhost, 127.0.0.1, dbserver, webserver, 192.168.1.140.
    wordpress@localhost
    wordpress@127.0.0.1
    wordpress@192.168.1.140
    wordpress@dbserver
    wordpress@webserver

    I can access the wordpress database from the the wordpress user account using the “mysql” command. I have used the following host configs in the wp-config.php file:

    define(‘DB_HOST’, ‘192.168.140.227’);
    define(‘DB_HOST’, ‘dbserver’);
    define(‘DB_HOST’, ‘webserver’);
    define(‘DB_HOST’, ‘1localhost’);
    define(‘DB_HOST’, ‘192.168.1.140’);
    define(‘DB_HOST’, ‘127.0.0.1’);

    I still get the “Error establishing a database connection”

    Any clues what I’m missing?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter bondoman

    (@bondoman)

    I typo’ed the 4th of the entries:

    define(‘DB_HOST’, ‘1localhost’);
    should have read:
    define(‘DB_HOST’, ‘localhost’);

    Sorry.

    Looks like you are just redefining the DB_HOST var?

    What are your values for the database, user and password? The user must be database specific with all rights granted.

    Thread Starter bondoman

    (@bondoman)

    I have the names dbserver & webserver in the DNS tables. The system responds with the default webpage to either domain name.
    I have a link to the wordpress directory in the top level directory of /var/www/html. Setting the browser to webserver.my.net or dbserver.my.net shows the default webpage. webserver.my.net/wordpress or dbserver.my.net or 192.168.1.140/wordpress gets the error response.

    Thread Starter bondoman

    (@bondoman)

    They are the same user name and password as I used to verify the login and access using the “mysql” command.

    Thread Starter bondoman

    (@bondoman)

    Using the username and password with the “mysql” command allows me to view the database and tables.

    Thread Starter bondoman

    (@bondoman)

    I just did not drop those lines into this thread. Sorry for the confusion

    Thread Starter bondoman

    (@bondoman)

    Each of the DB_HOST entries that I dropped into this thread was a separate attempt to get this working.

    Did you update the config file as per – Edit Config

    and follow – Installing WordPress

    Which has the mysql client process below:

    $ mysql -u adminusername -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5340 to server version: 3.23.54
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql> CREATE DATABASE databasename;
    Query OK, 1 row affected (0.00 sec)
    
    mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname"
        -> IDENTIFIED BY "password";
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> EXIT
    Bye
    $
    Thread Starter bondoman

    (@bondoman)

    For clarity:

    // ** MySQL settings ** //
    define(‘DB_NAME’, ‘wordpress’);
    define(‘DB_USER’, ‘root’);
    define(‘DB_PASSWORD’, ‘1pass1word1’);
    define(‘DB_HOST’, ‘localhost’);
    define(‘DB_CHARSET’, ‘utf8’);
    define(‘DB_COLLATE’, ”);

    Line four is the line that I changed in each attempt to get this to work & what I showed in my first post.

    Thread Starter bondoman

    (@bondoman)

    [root@mfg-dbserver ~]# mysqlshow wordpress -u wordpress -p1pass1word1
    Database: wordpress
    +——–+
    | Tables |
    +——–+
    +——–+

    Generally root does not work (strange but true) – you need a database specific user. Try creating a database specific user and granting all privileges for your database which you call ‘wordpress’.

    Thread Starter bondoman

    (@bondoman)

    I forgot that I just changed the user name in an attempt to debug this to root. Should read “wordpress” instead of root. I figured if the root couldn’t access it wasn’t a permission thing.

    Thread Starter bondoman

    (@bondoman)

    my database specific user is call “wordpress” that is the user name that I used to test access with the ‘mysql’ & ‘mysqlshow’ commands. That works as far as mysql is concerned but not from a wordpress setup. That is what I’m not clear about.

    I verified that I can access the DB from a different system.

    [root@Centos63 CentOS]# mysql -h webserver -u wordpress -p wordpress -p1pass1word1
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 17
    Server version: 5.1.66 Source distribution

    Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

    mysql> show tables
    -> ;
    Empty set (0.00 sec)

    mysql> exit;
    Bye

    Looks like you are getting valid results from the command line. Have you tried connecting via a PHP script for debugging purposes?

    Something like below or even use the MySQL or MySQLi API which would be closer to WordPress (obviously insert or assign your values for $hostIn, $dbIn, $userIn and $passwordIn):

    <?php
    $hostIn     = 'localhost';
    $dbIn       = 'testconnect';
    $userIn     = 'testuser';
    $passwordIn = 'testpass';
    try {
        $MySQLDataBaseLink = new PDO(
    	"mysql:host=" . $hostIn . ";dbname=" . $dbIn, $userIn,
    	$passwordIn);
        $MySQLDataBaseLink->setAttribute(PDO::ATTR_ERRMODE,
    	PDO::ERRMODE_EXCEPTION);
        echo 'Yippee - good connection';
    } catch(PDOException $e) {
        echo '<h3>Catch Connect Error--->>> '
    	. $e->getMessage() . '</h3>';
        return false;
    } //End Try Catch
    ?>

    Thread Starter bondoman

    (@bondoman)

    I get back:

    [root@dbserver ~]# php test.php
    Yippee – good connection
    [root@dbserver ~]#

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Centos 6.3 MySQL WordPress = Error establishing a database connection’ is closed to new replies.