• I’m using Linux Mint 13 (Ubuntu 12.04 based) and trying to install a local development environment of a WordPress production project which right now is in an amazon EC2 instance.

    First, I cloned WP project from its bitbucket repository.

    After, I made a db environment backup with:

    mysqldump -u root -p --lock-tables=false --all-databases > dump-$( date '+%Y-%m-%d_%H-%M-%S' ).sql

    Then I imported it to my computer with:

    scp my-server:~/db_backups/db_backup.sql ~/mylocalfolderforbackups

    I installed the db environment backup in my local mysql with:

    mysql -u root -p < db_backup.sql

    My wp-config.php is filled as following (thought I don’t know if my WP copy uses wp-config.php.prod instead):

    define('DB_USER', 'root');
    define('DB_PASSWORD', 'password'); (where I put the right password for root user)
    define('DB_HOST', 'localhost');
    define('WP_HOME', 'http://localhost');
    define('WP_SITEURL', 'http://localhost');

    I’ve restarted apache and mysql but when I try to access to http://localhost/my-project/ it returns “Error establishing a database connection”. I don’t find the issue… Do you have an idea? Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You are welcome,

    Are you missing the DB_NAME definition from your wp-config.php ?

    From wp-config-sample.php :

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'database_name_here');
    
    /** MySQL database username */
    define('DB_USER', 'username_here');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'password_here');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');

    Thread Starter miguelitomola

    (@miguelitomola)

    Thank you santeven but I forgot to put the DB_NAME on the post whereas it is right on the code (I supose).
    It is like this:
    define('DB_NAME', 'prod_db'); //because I've restored the production db backup

    The DB_NAME doesn’t seem to be the problem.

    For what it is worth, other thing I noticed, you dumped –all-databases … then imported and installed same. I probably would have dumped only prod_db and continued same from there.

    I’m probably not so sophisticated as you with SQL, it seems to me you only need to work with the one database as opposed to the “whole environment”.

    Also I never use root in wp-config.php, I create another user and grant all … then later if I want I can create a totally separate second wordpress and use a separate third user.

    First, I cloned WP project from its bitbucket repository.

    Perhaps this part complicates the scenario beyond my understanding. anyway I found this: http://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/

    Good Luck

    Thread Starter miguelitomola

    (@miguelitomola)

    Thank you santeven. This is my first time doing this, and I didn’t know if I needed the whole mysql environment or not. I’m going to redo this only with the prod_db as you say.

    About the user, I knew it but I was doing a test with root.

    I’ll have a look to the article.

    I keep trying.

    Regards

    Have you verified that the db imported successfully?
    Check https://dev.mysql.com/doc/refman/5.5/en/getting-information.html for a few of the commands (though it looks like you already have a good grasp on that). Also – be good to make sure there are no restrictions with root access to the db.

    It might even be worth writing a small php script to make sure to isolate the issue outside of wordpress.

    <?php
    $username = "root";
    $password = "";
    $hostname = "localhost"; 
    
    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password)
      or die("Unable to connect to MySQL");
    echo "Connected to MySQL<br>";
    ?>

    Use this to make sure you can at least connect properly to MySQL.

    Then –

    <?php
    //select a database to work with
    $selected = mysql_select_db("yourdbname",$dbhandle)
      or die("Could not select examples");
    ?>

    Use this to make sure you can connect to the actual database.

    If both are successful, then you may want to recheck the wpconfig again for extra spaces etc.

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