Reputation: 1098
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
Upvotes: 8
Views: 9452
Reputation: 6127
XAMPP mac has the default settings to store mysql.sock another location. Just change it :)
$ vim /applications/xampp/xamppfiles/etc/my.cnf
[client]
#password = your_password
port =3306
#socket =/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
socket =/tmp/mysql.sock <---------
...
[mysqld]
user=mysql
port=3306
#socket =/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
socket =/tmp/mysql.sock <---------
Restart mysql, then works.
Upvotes: 0
Reputation: 2842
Looks like your mysql server is not started. Use the following commands:
mysqld stop
mysql.server start
Upvotes: 0
Reputation: 1098
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.
Upvotes: 15
Reputation: 133
Not sure how you get a list of running programs on a mac but you should try and verify that mysqld is actually running. (on linux "top -bn1 | grep mysql" would normally show a line of info if it is running, or nothing if it is not.)
You could also try stopping mysqld and see if /tmp/mysql.sock vanishes. If it doesn't then try deleting it and restarting mysql to see if it appears again. (it should)
Do you have any log files that might show what is going on?
Upvotes: 0