• Hello!

    I have installed MAMP on my pc running windows 7 to develop a local website using wordpress. I have access to phpmyadmin so my database server is not down, and I am also 110% sure that my wp-confq.php file is accurate with the correct database, host, username, and password. I created a database called “wordpress” and am on the localhost. By default I am under the impression that I am to use “root” for the username and password.

    I keep getting the following error,

    “Error establishing a database connection

    This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

    Are you sure you have the correct username and password?
    Are you sure that you have typed the correct hostname?
    Are you sure that the database server is running?”

    I have checked all of my firewall settings as well to make sure they are not blocking access to the server.

    I have searched several forums but cannot seem to find the answer after two days of research. Thank you in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator t-p

    (@t-p)

    In nutshell, you’re getting this error because WP is unable to establish a database connection. Reason why WP is unable to establish a database connection can vary. It could be that your database login credentials are wrong or have been changed. It could be that your database server is unresponsive. It could be that your database has been corrupted. Majority of the times this error happens because of some sort of server error. Also, there could be other factors as well. To troubleshooting this problem:
    – double check your wp-config.php file settings for the database name, database username and database password, and the host name (e.g., “localhost” Vs. something else). This is where most errors occur.
    – Then make sure wp-config.php is in right location.
    – Then check that you don’t need to change the database host from “localhost” to something else. You can get that info from your hosting provider.
    – Check you have actually created a database with the same database name as is in your wp-config.php file.
    – Last, but not least, if all that information is correct your database probably has a problem with it.
    – If the error is intermittent then it’s your server. What’s happening is that the web server and/or the database server are gettign overloaded and the connection is droping out or is refused for a short time. That gives you the database error as the website can’t connect to the database. To fix this, you’ll need to talk to your hosting company as they are the only ones that can do anything about hardware issues like this.
    – There are also many threads on this topic on these forums: https://www.ads-software.com/search/Error+establishing+a+database+connection?forums=1

    useful WP codex:
    https://codex.www.ads-software.com/Installing_WordPress_Locally_on_Your_Mac_With_MAMP
    https://codex.www.ads-software.com/Installing_WordPress#Installing_WordPress_on_your_own_Computer ; https://codex.www.ads-software.com/WordPress_Installation_Techniques#Installing_WordPress_Locally ; https://codex.www.ads-software.com/Installing_WordPress

    Those are indeed the correct values for the default database user for MAMP on Windows.

    Database Name: wordpress
    User Name: root
    Password: root
    Database Host: localhost
    Table Prefix: wp_

    From the MAMP Control Panel, if you click on Open Start Page and you get the MAMP home page, then indeed both servers are up and running (both boxes on the control panel should also be ‘solid’).

    The primary reason to still get the connection error is if the values in wp-config are not entered correctly.

    Did you manual enter the values in wp-config or were they entered in the database screen during the WP installation process? For example, a space after root will give you this error ??

    Quadruple check the values in wp-config ??

    Cheers!
    Lyle

    Hi,

    Also make sure file rights are ok – for directories from root.

    It can create issues if WP can not writes some files.

    Thread Starter stephrek

    (@stephrek)

    Thank you all for your replies! But unfortunately, everything all of you have mentioned I have done and assured were correct. I have 100% access to my database and there are no signs of any error. Both the server lights are running green in MAMP so I am not sure how to fix an error I can not see.

    Also @snifflevalve I have both manual entered the vaulues for thw wp-config file and also tried to have them entered in the database screen.

    I have the wp.config file in the same place the sample was when originally downloading wordpress.

    @digico what do you mean make sure the files are ok? What should I look for?

    I am on my work computer and IT couldn’t help me figure this out either. ??

    Digico Paris

    (@digico-paris)

    @stephrek

    Hi,

    I meant by that, make sure you have full rights to read/write every folder where you installed WordPress.

    On a Windows 7 and if only for local tests, you can try this, assuming your root directory is “WordPresslocal”:

    – right click folder > properties > disable “read-only” check box > on same window click “Apply”.
    – Another pop-up will appear asking you if this is also for sub-folder and files, check YES and restart MAMP later

    I hope it will help, this is more or less the same as doing a CHMOD 777 on Linux,

    Also if you can, it’s often easier to open an account on a real web host, for testing, I know some good VPS at 3€/month for example – but not here to make advertising.

    Good luck,

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