elite0226
elite0226

Reputation: 173

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock'

I have just installed xampp on Mac.

I was trying to import an existing .sql file to MySQL DB on phpMyAdmin.

It was a success.

But I cannot connect MySQL using mysql browser like Sequel Pro.

I think this is because of ERROR (2002)

This is the result when I type mysql on the terminal.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")

Please help me how to fix this issue.

Upvotes: 1

Views: 13223

Answers (1)

Fatih Aktaş
Fatih Aktaş

Reputation: 1564

Have you checked it out here. It means either the MySQL server is not installed/running, or the file mysql.sock doesn’t exist in /var/lib/mysql/.

There are a couple of solutions for this error.

  1. First, check to see whether mysqld service is running or not. If not, start it:
service mysqld start
Then try to connect again.
  1. Try to connect to 127.0.0.1 instead of localhost

If you connect to localhost, it will use the socket connector, but if you connect to 127.0.0.1 the TCP/IP connector will be used. So when the socket connector is not working, try connecting to 127.0.0.1 instead.

  1. Edit file my.cnf

Find the file my.cnf (usually in /etc/) to edit and add these following line:

[mysqld]

socket=/var/lib/mysql/mysql.sock 

[client]

socket=/var/lib/mysql/mysql.sock
Restart mysql and connect again.
  1. Symlink

In some cases, you mysql.sock might be located in another folder. You have to find and symlink it. You might find it in /tmp/mysql.sock or /data/mysql_datadir/mysql.sock

For example, your file is located as in /tmp/mysql.sock

Then symlink it:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Restart mysql and connect again. 

Upvotes: 3

Related Questions