Title: Error establishing a database connection
Last modified: August 30, 2016

---

# Error establishing a database connection

 *  [sonofadoc](https://wordpress.org/support/users/sonofadoc/)
 * (@sonofadoc)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-698/)
 * I’m using a Mac and MAMP for the first time installing WP so I’m on unfamiliar
   ground. I used the terminal to access mysql database using the following command:
   /
   Applications/MAMP/Library/bin/mysql –host=localhost -uroot -proot. I believe 
   this says I entered my username as ‘root’ and the password as ‘root’. So in my
   wp-config file this is what I entered into those fields but I’m still not able
   to access the database in order to set up WP. Any help will save me from a bullet
   in the brain (just kidding).
 * I was able to create the database without a problem and also access mysql via
   the terminal so the username and password I entered into the wp-config matches
   that of my access into the mysql database.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [LyleChamney](https://wordpress.org/support/users/lylechamney/)
 * (@lylechamney)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-698/#post-6372345)
 * Did you enter the database name that you created?
 * Did you use a plain text editor to enter the values in wp-config.php?
 * Not sure why one would use the terminal for the db when using MAMP as it is so
   easy to use the supplied phpMyAdmin from the Tools menu on the MAMP Start Page
   🙂
 * Create the new, empty database and then run the install with `http://localhost:
   8888/name-of-folder` and enter the db connection details on the page in the setup
   process.
 *  Thread Starter [sonofadoc](https://wordpress.org/support/users/sonofadoc/)
 * (@sonofadoc)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-698/#post-6372358)
 * Thanks Lyle,
 * I’ll address the enquiries in the order they appear.
 * Q. Did you enter the database name that you created?
 * A. I created the database in the terminal and it exists. The database name is
   in the config file in DB_NAME ‘name of database’ is the same name of the database
   I created in the mysql terminal.
 * Q. Did you use a plain text editor to enter the values in wp-config.php.
 * A. I’m using Text-Mate so it should be OK out of the box Although text-mate is
   also a new app to me as I’ve been using notepad++ on a windows machine so it’s
   possible I may need to configure it in some way as far as line endings or little
   endian big endian or some such.
 * Statement: Not sure why one would use the terminal for the db when using MAMP
   as it is so easy to use the supplied phpMyAdmin from the Tools menu on the MAMP
   Start Page 🙂
 * Response: I actually first learned to create databases via the terminal so it’s
   a natural inclination for me to do so. Also, why use that big clunky program 
   when you can just type CREATE DATABASE db_name; and be done with it?
 * I’ll try again from scratch looking at your instructions Lyle. Thanks for the
   hand.
 * UPDATE: One thing I discovered after my last post last night was I couldn’t figure
   out what my password and username was, because I didn’t remember creating either
   one during the setup process. The last thing I tried was leaving the username
   and password fields blank (in the wp-config file) and then I got a different 
   error message when going to the URL localhost/example/wp-activate.php. The message
   said was able to access the server so the username and password was ok, but couldn’t
   connect to that particular DB_NAME. I know it exists for the simple reason when
   I enter SHOW DATABASES; in the terminal – there it is. To double check I went
   into phpMyAdmin panel and it is there also. So there is no question it exists
   so I can’t figure why WP and mysql can’t find it.
 *  [LyleChamney](https://wordpress.org/support/users/lylechamney/)
 * (@lylechamney)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-698/#post-6372419)
 * The default database user for MAMP is root with root as the password.
 * Not really sure what is up other than this URL:
 * `localhost/example/wp-activate.php`
 * In a default MAMP installation, the Apache port is 8888 which would make the 
   above `localhost:8888/example/wp-activate.php` and the default web root is `htdocs`.
 * This is my “famous” 3 minute WP install with MAMP 🙂
 * – default MAMP install for ports and web root
    – start MAMP and both servers –
   MAMP Start Page > Tools > phpMyAdmin – create new, empty database (`wordpress`
   for this example) – copy the the `wordpress` folder which was extracted from 
   the WP ZIP to Application/MAMP/htdocs – `http://localhost:8888/wordpress` to 
   start the installation – at the database page:
 * — Database Name: wordpress
    — User Name: root — Password: root — Database Host:
   localhost (or 127.0.0.1) — Table Prefix: wp_ (leave as-is) — Submit
 * – Run the Install
    – Site Title: whatever – Username: a user name of your choosing
   to log into the WP site – Password, twice: of your choosing – Your E-mail: a 
   properly formed email address – Privacy: un-check for local – Install WordPress–
   Log in 🙂
 * Works first time, every time 🙂
 *  Thread Starter [sonofadoc](https://wordpress.org/support/users/sonofadoc/)
 * (@sonofadoc)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-698/#post-6372423)
 * Well thanks Lyle,
 * I’ll give it a whirl, there may be something along the way I didn’t do correctly
   and I may see what it is as I follow your instruction. As far as the URL goes
   localhost:8888 you are given the option to change that in MAMP to just localhost/.
   I did forget to mention that the server was working fine as I had some static
   web pages in the htdocs directory that loaded right up, and the index.php file
   loaded up OK. It is the WP database that I’m having trouble with.
 * Thanks again for the famous 3 minute install and I’ll let you know how I fare
   with it.
 *  Thread Starter [sonofadoc](https://wordpress.org/support/users/sonofadoc/)
 * (@sonofadoc)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-698/#post-6372475)
 * Easy peezy lemon squeezy – as you said it would be. I’m up and running with MAMP
   and WP.
 * Thanks for the help Lyle! Take care.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Error establishing a database connection’ is closed to new replies.

## Tags

 * [connection](https://wordpress.org/support/topic-tag/connection/)
 * [database](https://wordpress.org/support/topic-tag/database/)

 * In: [Localhost Installs](https://wordpress.org/support/forum/localhost-installs/)
 * 5 replies
 * 2 participants
 * Last reply from: [sonofadoc](https://wordpress.org/support/users/sonofadoc/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-698/#post-6372475)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
