Mac上用 homebrew 装 mysql,完美解决 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 报错问题

新手学后台,打算用MySQL数据库

用homebrew安装mysql(Mac自带homebrew)


brew install mysql

完成后首次登陆


mysql -u root

一般都会报这个错

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

然后网上各种找教程,发现就是mysql.sock这个文件的路径问题,

解决办法:

修改/usr/local/etc/my.cnf文件(如果没有自创建),将文件里面socket的路径指向你mysql的安装路径,我复制了很多教程,结果还是不行,原因是大家的安装路径好像不太一样,你必须找到你的路径,(2017.11.28, mysql版本5.7.20)我的路径是在/usr/local/var/mysql/

Mac上用 homebrew 装 mysql,完美解决 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 报错问题_第1张图片
image

所以我的/usr/local/etc/my.cnf文件修改如下图

Mac上用 homebrew 装 mysql,完美解决 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 报错问题_第2张图片
image

修改好了,保存之后,再次尝试登陆


mysql -u root

好了,完美解决

Mac上用 homebrew 装 mysql,完美解决 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 报错问题_第3张图片
image

网上解决办法很多,但是不一定对你起作用,关键是要找到你的mysql路径,把教程中的换成你的就可以了

你可能感兴趣的:(Mac上用 homebrew 装 mysql,完美解决 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 报错问题)