Every time I run XAMPP and try to run $mysql -u root -p
, its throwing me an error which is:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I am using XAMPP version 1.7.3 in Mac OS-10.9. Starting Apache and MySQL is not a problem and I have confirmed Apache has started by going to activity monitor.
Few things I tried:
checked if MySQL is running by typing this command in terminal: mysqladmin -u root -p status
. Result was:
mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
I checked and found mysql.sock file in /var/mysql/mysql.sock
.
Things that could have triggered this error but cant say what is wrong:
Without fixing this problem I am not able to do any development locally and connecting MySQL in PHP script seems impossible. So any help will be appreciated.
Here is error_log file from /applications/xampp/xamppfiles/logs/error_log
:
[Sat Nov 02 09:56:31 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 09:56:39 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 09:56:40 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 09:56:40 2013] [notice] Digest: done
[Sat Nov 02 09:56:40 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 12:55:47 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 13:40:16 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 13:40:18 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 13:40:18 2013] [notice] Digest: done
[Sat Nov 02 13:40:18 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 15:12:39 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 20:54:41 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 20:54:43 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 20:54:43 2013] [notice] Digest: done
[Sat Nov 02 20:54:44 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 21:10:53 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 21:10:57 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 21:10:58 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 21:10:58 2013] [notice] Digest: done
[Sat Nov 02 21:10:58 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 21:31:39 2013] [notice] caught SIGTERM, shutting down
[Sat Nov 02 21:31:44 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 02 21:31:47 2013] [notice] Digest: generating secret for digest authentication ...
[Sat Nov 02 21:31:47 2013] [notice] Digest: done
[Sat Nov 02 21:31:47 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Sat Nov 02 21:45:07 2013] [notice] caught SIGTERM, shutting down
[Sun Nov 03 08:50:06 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sun Nov 03 08:50:09 2013] [notice] Digest: generating secret for digest authentication ...
[Sun Nov 03 08:50:09 2013] [notice] Digest: done
[Sun Nov 03 08:50:10 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
Here are some reasons the Can't connect to local MySQL server error might occur: mysqld is not running on the local host. Check your operating system's process list to ensure the mysqld process is present. You're running a MySQL server on Windows with many TCP/IP connections to it.
Open macOS system preferences and select the MySQL preference panel, and then execute Start MySQL Server. The Instances page includes an option to start or stop MySQL, and Initialize Database recreates the data/ directory.
Finally manage to solve it.
First I was looking on wrong directory, I should have looked into /applications/xampp/xamppfiles/
.
List of things I did:
there was not tmp folder under /applications/xampp/xamppfiles, so I created it (mkdir tmp).
I searched for mysql.sock file and found it under /applications/xampp/xamppfiles/var/mysql/mysql.sock
.
As mysql server connection was not working via socket /tmp/mysql.sock
, I used following command to point my /applications/xampp/xamppfiles/var/mysql/mysql.sock
to /tmp/mysql.sock
file.
So this command did the trick:
ln -s /applications/xampp/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock
mysql -u root -p
, I can get into mysql console. And I also tried connecting mysql from php script and its running ok.After pulling hair for a day and half I finally managed to get it working hope people will find this helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With