Support » Localhost Installs » Error establishing a database connection

  • Resolved reneekelly

    (@reneekelly)



    Installing WordPress Locally – using MAMP (v.3.8)
    Started process with new version of both on Dec. 24, 2015
    So far I have:
    1) Downloaded WordPress 4.4

    2) Launched MAMP

    3) Using MAMP’s phpMyAdmin created a new database – which I named wordpress44

    4) Unzipped the WordPress folder and placed it in my MAMP application folder’s htdocs folder.

    5) Opened up the wp-config-sample.php file and filled in the required information –

    define(‘DB_NAME’, ‘wordpress44’);

    /** MySQL database username */
    define(‘DB_USER’, ‘root’);

    /** MySQL database password */
    define(‘DB_PASSWORD’, ‘root’);

    /** MySQL hostname */
    define(‘DB_HOST’, ‘localhost’);

    6) Saved my edited file as wp-config.php.

    7) Made sure MAMP is running & opened up firefox and point it to: localhost:8888/wordpress – (which is the name of the wordpress folder)

    & I receive the message:
    Error establishing a database connection

    I have been on all the help threads I can find – 12 hrs of troubleshooting using existing suggestions & I am still stuck.

    I truly appreciate help in solving this so I can install wordpress for the first time. Thank you for time & assistance.

Viewing 15 replies - 1 through 15 (of 22 total)
  • Are you sure that your MYSQL is on localhost? Try your PC IP address. You can also try; localhost:3306, making sure you are connecting to the right port.

    /** MySQL database password */
    define(‘DB_PASSWORD’, ‘root’);

    i hope you put wrong :)Remove Database password.

    Try to put on this..

    /** MySQL database password */
    define(‘DB_PASSWORD’, ‘’);

    I forgot to add that I am working on a Mac – Os X Yosemite v. 10.10

    Re: localhost:
    I attempted that before & tried again with your suggestion & still the same message.

    When I go open MAMP, go to phpMyAdmin (under tools) & click on the created database (wordpress44) under Privileges it shows
    user – root
    host – localhost

    When I click on status it reports:
    Network traffic since startup: 279.4 KiB

    This MySQL server has been running for 4 days, 13 hours, 59 minutes and 27 seconds. It started up on Dec 25, 2015 at 03:24 AM.
    Traffic ø per hour
    Received 75.9 KiB 706 B
    Sent 203.5 KiB 1.9 KiB
    Total 279.4 KiB 2.5 KiB
    Connections ø per hour %
    max. concurrent connections 1 — —
    Failed attempts 43 0.39 45.26%
    Aborted 0 0 0%
    Total 95 863.71 m 100.00%

    I also cut & pasted define(‘DB_PASSWORD’, ‘’); adding root as password that was also suggested & still the same message.

    Hi,

    does root have all permissions to the database and the root is assigned to that wordpress44?

    @reneekelly, also thinking about this; if you go to; http://localhost:8888/MAMP/?language=English in your browser, what’s the database info you see; username, password, local host,…. use those within your configs. See if everything is correct and up to that info page MAMP gives you.

    You can install wordpress manually. I think it’s better for you.

    1) Unzipped the WordPress folder and placed it in my MAMP application folder’s htdocs folder.

    2. Create Database using “phpmyadmin”
    3. call link on your browser ” localhost/wordpress(wp folder name)
    4. select language
    5. set database name ” “
    6. set usernaem ” root”
    7. password blank

    that it…..

    Hi there, I appreciate your time.
    I’m sorry I didn’t include that in the previous post.

    Database: wordpress44
    User – root
    Host – localhost
    Type – global
    Privileges – all privileges
    Grant – yes

    The correct database, user & host are in my configs.
    However, where do I go to double-check the password (in phpMyAdmin)?

    When you are working on the localhost. Don’t need database password.

    Now just you on this for install wordpress.

    Database name : wordpress44
    Username : root
    password : blank
    host name: localhost

    When you are working on the web server then you can create database password.

    so just to recap; you’ve tried to restart both apache and mysql, you’ve closed down MAMP completely and ran it again, you’ve also rebooted your mac as well, checked config php file and has proper stuff in there, correct?

    Okay, I’m following your instructions (officialsabbir)

    In my configs: (cutting & pasting here)
    define(‘DB_NAME’, ‘wordpress44’);

    /** MySQL database username */
    define(‘DB_USER’, ‘root’);

    /** MySQL database password */
    define(‘DB_PASSWORD’, ‘’);

    /** MySQL hostname */
    define(‘DB_HOST’, ‘localhost’);

    /** Database Charset to use in creating database tables. */
    define(‘DB_CHARSET’, ‘utf8’);

    /** The Database Collate type. Don’t change this if in doubt. */
    define(‘DB_COLLATE’, ”);

    I am still getting the error message whether I use:
    localhost:8888/wordpress
    or change the port setting & use:
    localhost/wordpress/

    Regarding lastest post (Artur Bobinski):
    I have closed down MAMP completely and ran it again, I have rebooted my computer, but will do that again now & report back. (Should I consider trashing both MAMP & wordpress 4.4 & starting over with the downloads?)
    How do I restart both apache and mysql?

    @reneekelly,

    I wouldn’t trash MAMP nor WordPress … your simply not having the right connection settings or privileges to connect to you DB.

    Have you tried specifying the port of MYSQL;

    /** MySQL hostname */
    define('DB_HOST', 'localhost:3306');

    I mean its stretching it but possible that it needs the port

    btw, you still need the following even if local;

    /** MySQL database username */
    define('DB_USER', ‘root’);
    
    /** MySQL database password */
    define('DB_PASSWORD', ‘root’);

    to connect since root user has a password root assign to it. Just tested it on my end and it kept kicking me out without using the password or empty password.

    here’s my local wp-config.php file with MAMP;

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'test');
    
    /** MySQL database username */
    define('DB_USER', 'root');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'root');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');
    
    /** Database Charset to use in creating database tables. */
    define('DB_CHARSET', 'utf8mb4');
    
    /** The Database Collate type. Don't change this if in doubt. */
    define('DB_COLLATE', '');

    ahh and what do you have on the following line; does it look something like this;

    $table_prefix = 'wp_';

    so in your case, your config file should look like this;

    <?php
    /**
     * The base configuration for WordPress
     *
     * The wp-config.php creation script uses this file during the
     * installation. You don't have to use the web site, you can
     * copy this file to "wp-config.php" and fill in the values.
     *
     * This file contains the following configurations:
     *
     * * MySQL settings
     * * Secret keys
     * * Database table prefix
     * * ABSPATH
     *
     * @link https://codex.wordpress.org/Editing_wp-config.php
     *
     * @package WordPress
     */
    
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'wordpress44');
    
    /** MySQL database username */
    define('DB_USER', 'root');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'root');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');
    
    /** Database Charset to use in creating database tables. */
    define('DB_CHARSET', 'utf8mb4');
    
    /** The Database Collate type. Don't change this if in doubt. */
    define('DB_COLLATE', '');
    
    /**
     * WordPress Database Table prefix.
     *
     * You can have multiple installations in one database if you give each
     * a unique prefix. Only numbers, letters, and underscores please!
     */
    $table_prefix  = 'wp_';
    
    /**
     * For developers: WordPress debugging mode.
     *
     * Change this to true to enable the display of notices during development.
     * It is strongly recommended that plugin and theme developers use WP_DEBUG
     * in their development environments.
     *
     * For information on other constants that can be used for debugging,
     * visit the Codex.
     *
     * @link https://codex.wordpress.org/Debugging_in_WordPress
     */
    define('WP_DEBUG', false);
    
    /* That's all, stop editing! Happy blogging. */
    
    /** Absolute path to the WordPress directory. */
    if ( !defined('ABSPATH') )
    	define('ABSPATH', dirname(__FILE__) . '/');
    
    /** Sets up WordPress vars and included files. */
    require_once(ABSPATH . 'wp-settings.php');

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