What to do if phpMyAdmin from the MAMP installation fails to access MySQL?
On my macOS devices I use MAMP app by appsolute GmbH for local web development. But sometimes there are problems. When I try to access the phpMyAdmin web page located at localhost/phpMyAdmin/index.php
, the following error message appears:
I’m using version 5.1 of the MAMP app, but in your case there can be any other version of the MAMP app. If you use the non-standard version of the app, but the PRO one, then in the following steps, replace “MAMP” with “MAMP PRO”, respectively.
What causes this problem
The reasons for this problem with access to the phpMyAdmin web page can be different in different cases. To find out the exact cause of the problem, you need to look in the phpMyAdmin error message. Here are mine:
Cannot connect: invalid settings
mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES)
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.
In my case, it’s my fault. Recently I bought a new computer and I decided not to transfer the settings from the old computer, but to set up a new computer from scratch. Thus, after changing the password of the MySQL root user, I forgot to set up the phpMyAdmin configuration file.
How to solve it
To solve this problem all we need to do is change the phpMyAdmin configuration file to use the actual password of the MySQL root user. To do this we have two methods. The first method is using Finder and the TextEdit app, and the second is using the Terminal app. Use the one that is convenient for you.
In this solution we will use the Finder and the TextEdit app. You do not need to download and install anything, because it is already built into every macOS.
-
If the MAMP app is running, click the
Stop Servers
button and quit the app. -
In the Finder, go to the folder
Applications
->MAMP
->bin
->phpMyAdmin
. -
Open the file
config.inc.php
in a text editor. As a text editor, I use the TextEdit app, but you can use any other editor. The contents of the file may seem complicated in understanding, but do not worry, we will not change a lot of things. - Use the search to find the line below. In my case, this line was 87th.
$cfg['Servers'][$i]['password'] = 'root'; // MySQL password (only needed
-
Replace
'root'
with the actual password of the MySQL root user. -
Save the changes and close the file
config.inc.php
. -
Launch MAMP and click the
Start Servers
button. - Try to access the phpMyAdmin web page through the Safari browser.
The phpMyAdmin web page located at
localhost/phpMyAdmin/index.php
.
This is another method to do the same thing as in the previous solution (№1), but with use the Terminal app. You do not need to download and install anything, because it is already built into every macOS.
-
If the MAMP app is running, click the
Stop Servers
button and quit the app. -
Launch the Terminal app from the Utilities folder of your Applications folder, or use Spotlight to find it.
- Enter the command below to open the file
config.inc.php
. As a text editor, I use thenano
, but you can use any other editor.nano /Applications/MAMP/bin/phpMyAdmin/config.inc.php
The contents of the file may seem complicated in understanding, but do not worry, we will not change a lot of things.
- Use the search to find the line below. In my case, this line was 87th.
$cfg['Servers'][$i]['password'] = 'root'; // MySQL password (only needed
-
Replace
'root'
with the actual password of the MySQL root user. -
Save the changes and close the file
config.inc.php
. -
Launch MAMP and click the
Start Servers
button. - Try to access the phpMyAdmin web page through the Safari browser.
The phpMyAdmin web page located at
localhost/phpMyAdmin/index.php
.
Conclusion
That’s it, you’re done. Now the phpMyAdmin web page should be accessible without errors. So simple isn’t it?
If you are having trouble fixing this problem with the instructions above, but are being able to solve this problem with any another method please describe it in the comment section below. Thanks!
If this article has helped you solve the problem then please leave a comment
Thanks for reading!
Arthur is a designer and full stack software engineer. He is the founder of Space X-Chimp and the blog My Cyber Universe. His personal website can be found at arthurgareginyan.com.