#2002 Cannot log in to the MySQL server
Setting up PHP, MySQL and phpMyAdmin seems to be a trivial thing on mac. However, occasionally, it throws errors that are hard to debug. As the #2002 error.
My installation consisted of phpMyAdmin 3.4.4, MySQL 5.5 and PHP 5.3.4 under Mac OS X 10.6.8 (Snow Leopard).
Here a guide how to make things work.
You can follow this tutorial or download an automated PHP script which will test your system for PHP, Webserver and MySQL extension availability.
Note: You still need to edit some settings in the script.
First, make sure your MySQL Server is up and running.
Do a sample PHP script to test if you get an MySQL connection at all. Make additional changes to the script depending if you changed default settings. If you installed MySQL server with default options, changes will be minimal. The source of the script can be as follows:
<?php $db = mysql_connect("localhost", "root", "password"); // Make sure to include your chosen username and password during MySQL installation if (!$db) die('Could not connect' . mysql_error()); echo 'Connected successfully';
Make sure you include your MySQL Server chosen username and password. Review what kind of error MySQL gives you if any.
If the script says it can not connect to the database server, change localhost to 127.0.0.1 and try again.
That seems to be a problem under some environments. If that is the case, make sure to use the numeric IP (127.0.0.1) in the configuration of phpMyAdmin instead of localhost.
If you get a connection without errors, that means something is wrong with your phpMyAdmin settings.
In the setup script of phpMyAdmin (or config.inc.php depending if you prefer to edit the configuration file in a text editor), make sure you are using socket as Connection type.
Follow the phpMyAdmin quick install instructions if you did not yet setup phpMyAdmin.
Even if after this change you cannot login in your phpMyAdmin administrative interface:
Edit /etc/php.ini, and replace the occurrences of /var/mysql/mysql.sock with /tmp/mysql.sock
This will work if you have installed MySQL with default settings.
As of time of writing, phpMyAdmin 3.4.4 is the newest version. Always make sure you do have the latest version, not to miss bug fixes and new features. Download the latest phpMyAdmin.
If you do not understand some parts of this guide or want to share your opinion, feel free to leave a comment.