#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.
Thank you! This worked for me. I just renamed config.sample.inc.php to config.inc.php, and it worked for me.
hello i need help’
i tried all the solutions but still access denied every time i make a connection with mysql,
i think i’ve read and applied all the solution like changing the localhost to 127.0.0.1and changing the localhost to 127.0.0.1 on config.inc.php,my connection type is socket.i also check the c:\windows\system32\drivers\ and the localhost there is also 127.0.0.1..
i did everything but still went wrong..my o.s is windows..
this is the scenario..i used manual installation for mysql server but when i found out about xampp..i uninstalled it and used the mysql included from the xampp package..do you think
that is the reason of connection problem..
and this one makes me confused..
$db = mysql_connect(“localhost:3306″, “username”, “password”);
this line from the php script, am i supposed to put the username and password of my mysql server?or i set new username and password,its like i can put any new user name and password on this line
$db = mysql_connect(“localhost:3306″, “usename”, “password”);.
In the function mysql_connect() you should put the actual already existing username and password of your MySQL database. If it connects with any username and password, then your MySQL server is configured to accept any connection, without authentication.
i got it..
i think my mysql server is not configured to accept any connection, without authentication.
but what if i could no longer remember my exact username and password of my mysql database?
what would i do?
or as i a solution, may i set my configuration to accept any connection,without authentication? if that’s the right solution..please tell me how.
To reset your root password on Windows machine, follow instruction described here: http://dev.mysql.com/doc/mysql-windows-excerpt/5.0/en/resetting-permissions-windows.html
Further, if you want to access without password, you can add the password to my.cnf file. Check the configs here: http://dev.mysql.com/doc/refman/5.1/en/option-files.html
I cannot find socket.sock file anywhere. How can I recreate it ?
Pingback: MySQL server has gone away – where has it gone? | Mr Daz
Thank you! That worked perfectly
I have installed Xampp, now I want to install MySQL 5.4 for using it with glassfish server (net beans) for java uses but I could not install it. There is an error at security execution it says that root password does not match
You need to have root account privileges to install an MySQL server, are you sure you are entering the right root password?
In my case worked with localhost and tcp connection type, but the MySQL service had to be started (live it Automatic!).
Thank you very much!!!!
you saved the day
Splendid, thanks for this. My upgrade from 5.2.x to 5.3.20 broke all connections to “localhost”, but switching to 127.0.0.1 fixed things fine.
Jon, Glad it worked! I believe adding an appropriate entry into your hosts file will permit you to use “localhost” again. The location of the file depend on your operating system. Check this page for more info: http://en.wikipedia.org/wiki/Hosts_%28file%29
Great !! 127.0.0.1 Worked on SLES 11 SP2
Thanks!
Thank you!!! This is what fixed it for me:
“Edit /etc/php.ini, and replace the occurrences of /var/mysql/mysql.sock with /tmp/mysql.sock”
Great!