首页 > 代码库 > mac ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mac ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

好久不用mysql,今天突然想用的时候,

mysql -uroot -p

直接报了下面的错误

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)

mac可以在设置里面启动mysql,设置里面启动mysql的时候提示没有/usr/local/mysql/data的权限,

给予权限

sudo chown -R mysql:mysql  /usr/local/mysql

发现还是没用,但是发现mysql当时是配置了链接

qiweijieMacBook-Pro:~ qiweijie$ ll /usr/local/mysql

lrwxr-xr-x  1 _mysql  _mysql  27  2 26  2016 /usr/local/mysql -> mysql-5.7.11-osx10.9-x86_64

虽然给了mysql权限,还是只是给到了链接的权限,没有得到真正的mysql目录的权限

qiweijieMacBook-Pro:~ qiweijie$ ll /usr/local/mysql-5.7.11-osx10.9-x86_64/

total 48
...
drwxr-x---  16 qiweijie  staff    544 10  7 12:18 data
....

sudo chown -R mysql:mysql  /usr/local/mysql-5.7.11-osx10.9-x86_64/

这样就好了

 

mac ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)