phpMyAdmin is throwing a #2002 cannot log in to the mysql server phpmyadmin
If you're getting the #2002 Cannot log in to the MySQL server
error while logging in to phpmyadmin, try editing phpmyadmin/config.inc.php
and change:
$cfg['Servers'][$i]['host'] = 'localhost';
to:
$cfg['Servers'][$i]['host'] = '127.0.0.1';
Solution from Ryan's blog
Edit (20-Mar-2015):
Note that if you're on a fresh install, config.inc.php may not exist. You need to rename / copy config.sample.inc.php and then change the relevant line
This is old but as it is the first result in Google,
Please note that this also happens when your MySql service is down,
I fixed this by simply restarting MySQL Server using:
/etc/init.d/mysql restart
in SSH (Command is for a CentOS/CPanel server)
Background: I am using Linux Mint 13. In my case, this error happened when I restarted the computer and my DHCP assigned a new local IP address (from 192.168.0.2 to 192.168.0.4) to my desktop.
sudo gedit /etc/mysql/my.cnf
Update
bind-address = 192.168.0.2
to
bind-address = localhost
This fixed the problem. Enjoy.
This can also be caused if you forget (as I did) to move config.inc.php
into its proper place after completing the setup script.
After making the config
folder and doing chmod o+rw config
and going to localhost/phpmyadmin/setup
and following those steps, you need to go back to the command line and finish things off:
mv config/config.inc.php . # move file to current directory
chmod o-rw config.inc.php # remove world read and write permissions
rm -rf config # remove not needed directory
See full instructions at https://phpmyadmin.readthedocs.org/en/latest/setup.html
After trying all of the above suggestions here is what fixed my #2002 error.
Add the following line to your config.inc.php file and change the number to your MySQL port:
$cfg['Servers'][$i]['port'] = '3307'; // MySQL port
I had multiple mysql instances installed, and in this case, I had updated my.ini to run MySQL on port 3307, but had not updated phpMyAdmin to reflect the new port. In my case, the line for the port did not exist in the config.inc.php file, so I was not aware that it needed updating.