Summary
I am using MAMP Pro for maintaining local copy of my wordpress website. I am trying to have a separate wordpress installation, and it is giving a database connection error.
Details
I’m trying to define multiple hosts in MAMP Pro for separate wordpress installations. The default “localhost” works fine, but if I try to add another host, it doesn’t work properly.
Using the new host (wordpress.dev), the browser properly launches the wordpress installation page defined in the (wordpress.dev) directory, but after inserting the database name and credentials, it gives a connection error.
I’ve double checked the database name, username, password etc. I’ve also tried to run it using mysql root credentials. I’ve also given all global rights to the database user, database specific rights etc. But to no avail.
Since I’ve been using the default rights for the Document root in MAMP pro, I suspected that it could be a rights issue, I tried to assign all the rights to the System Administrator account or www but nothing worked.
If I press the “Web Start” button on Mamp Pro, the browser opens the following page (http://localhost/MAMP/?language=English) that describes Host as localhost.
The complete error states as
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 wordpress.dev. 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?If you’re unsure what these terms mean you should probably contact
your host. If you still need help you can always visit the WordPress
Support Forums.
Please keep in mind that the host “wordpress.dev” is present, and when I point it in the browser, it loads the defined directory but it is unable to connect to the database using that server.
I tested to remove the password from the database user and the error changes to this.
Canât select database
We were able to connect to the database server (which means your username and password is okay) but not able to select the mydb database.
Are you sure it exists?
Does the user myadmin have permission to use the mydb database?
On some systems the name of your database is prefixed with your username, so it would be like username_mydb. Could that be the problem?If you don’t know how to set up a database you should contact your host. If all else fails you may find help at the WordPress Support Forums.
Thanks for reading my question and any help is much appreciated.
After wasting much time, I came to know that I was forgetting to rename the configuration file from wp-config-sample.php to wp-config.php.
Although wordpress installation was asking the details to generate the configuration file but probably, the wordpress installation didn’t have the permissions to generate any file on my system.
I use MAMP + Mac OS
It works with these settings in wp-config.php