Support » Installing WordPress » Error establishing a database connection on Mac/MAMP Install

  • Resolved Pekae


    Trying to install WP 4.1with MAMP
    Followed several YouTube videos and also WP pages on doing the install, but continually get the same “Error establishing a database connection ” when I try to run install.php

    I’ve checked everything that all the help pages suggest and none of it works.

    I’ve trashed various installs and tried over again – same result!

    Any other suggestions would be gratefully received!
    (I’ve also tried Bitnami WordPress Stack and I can’t even get mySQL to start in that!!)


Viewing 14 replies - 1 through 14 (of 14 total)
  • Caleb Burks


    Automattic Happiness Engineer

    First you may want to make sure MySQL is running in MAMP.

    If it is, then you can check the database connect easily on your own. Head to the root folder of your WordPress install, (MAMP’s “htdocs” folder) and open up wp-config.php.

    The top should look something like this:

    // ** 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');
    /** 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', '');

    You need to change the first three lines of code. The username will be ‘root’ and the password is blank by default ”.

    To get the database name, go to http://localhost/phpmyadmin and create a new database and call it whatever you want, then add that name to the first line in the config file. And bam! It’s all set up.

    Edit: If there is no wp-config.php in the root folder, copy wp-config-sample.php and rename it to wp-config.php.

    Hi Caleb,
    Thanks for the pointers, but I tried all that already (numerous times). As I say, I’ve done clean installs and followed various youtube videos as well as several (different) “beginners guides” – always with the same result.

    I have double & treble-checked all of the parameters, but to no avail.

    In addition, by the way, when I check to ensure that the database is set up correctly, there are no tables in it – but I assume that thats what the install routine builds? (Which, of course, I can’t get to run!!)


    Have you tried going directly to http://localhost/wp-admin/install.php? You may have some limitation on redirecting to the installer via your local setup.

    The installer should ask you a few questions and install all the tables you will need.


    Hi –

    Doesn’t work – that’s the final step in the chain that always gives me that “Error establishing a database connection ” message, no matter what I do.

    Caleb Burks


    Automattic Happiness Engineer

    Looks like mamp isn’t starting up mysql.

    You can try downloading XAMPP instead.

    Hi – MAMP is starting mySQL and Apache – I can get to it to create a database, no problem, it’s just that final step 🙁

    I just reproduced your issue using my Mac, MAMP, and WordPress 4.1. All I had to do was install MAMP, drag the WordPress contents to /Applications/MAMP/htdocs, point my browser to http://localhost/wp-admin/setup-config.php, click Continue (for English language), click Let’s go!, and click Submit.

    The end result was a page stating “Error establishing a database connection”. My point here is that I hadn’t even created a database yet. So, I created a database named “wordpress” and followed the same instructions and once again, of course, I got the same error message.

    But this time it wasn’t because I had failed to create a database. This time it was because I failed to change the default WordPress setup User Name (i.e., username) and Password (i.e., password).

    So, as they say, “Thirds a charm” I tried again. This time changing the User Name to root and the Password to root and it worked. That is, I made it to the “All right, sparky! You’ve made it through this part of the installation.” page.

    I’m pretty sure you already knew all this Paul, but I just wanted to document how easy it is to get the dreaded “Error establishing a database connection” error message.

    A question that comes up in my mind for you is whether or not you’ve ever successfully setup a WordPress site using MAMP on your current computer’s operating system? Because, of course, if you have all we need to do is figure out what you did differently this time around. And, I know, sure, that’s the million dollar question but one worth pondering. 🙂

    P.S., For MAMP Preferences, what are your port settings? For example, mine are Apache 80, Nginx, 8887, and MySQL 3306. Moreover, for Web Server, Apache is selected, right? And the document root is Applications > MAMP > htdocs, right?

    Just making sure we’re all on the same page.

    P.P.S., Here are a few links dedicated to the infamous “Error establishing a database connection” error message just in case you’re still stuck:

    Note that if you are still having troubles, I would a) delete MAMP, b) delete MAMP preferences (~/Preferences/de.appsolute.MAMP.plist), c) install MAMP, d) Start Servers, e) create new database via phpMyAdmin named wordpress, f) drag new WordPress 4.1 contents to /Applications/MAMP/htdocs folder, g) go to http://localhost:8888, and h) follow all the instructions changing only the User Name from username to root and the Password from password to root. If this fails, WOW, I am not sure what else to do. My only guess being that somehow someway some bit of data within your wp-config.php file is wrong and/or, as theorized above, your MySQL database isn’t running.

    Hope something here help!

    If you check the Start Page of MAMP, it says right there that the default MySQL User and Password are both root 🙂

    These are the default values out of the box. And if you leave all the defaults set as installed (Apache port = 8888 and document root is Applications/MAMP/htdocs) then everything works ‘splendidly’ 🙂

    Although on can install a site directly in the document root, it is generally advised not to do so as it clutters up the directory. Best practice is to have your sites in their own folder within /htdocs.

    For example, if you placed your WP files in a folder named wordpress within /htdocs, you would then access it with:


    To sum up:

    – leave the defaults as installed for MAMP
    – place your site files in a folder within /htdocs

    Hope this helps anyone else having these sort of issues and chances are we won’t see you here with these questions 🙂

    Thanks to everyone for suggestions.

    Randy – Thanks for going the extra mile! Your latter post re uninstalling and clearing it all out worked – the only thing I did differently was instead of changing the wp-config manually, I went through the entire WordPress install, as you described and, hey presto – all good!

    Thanks again.


    Good to hear! You’re more than welcome Paul.

    Do be sure to mark this thread “resolved” using the dropdown in the sidebar. 🙂

    Done – Thanks Randy.


    I had this same problem and I had tried everything, it was driving me crazy! Thanks to Randy and Lyle, their solution worked.
    1. Deleting and reinstalling MAMP
    2. Leaving default ports and default folder to /htdocs
    3. Creating a new database
    4. Using username root and password root (instead of creating my own)
    5. Changing wp-config with this data and leaving everything else the same.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Error establishing a database connection on Mac/MAMP Install’ is closed to new replies.