长久不用的mysql报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

时间:2021-05-08 00:30:38

mac上安装过mysql:

长久不用的mysql报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

然而,尝试连接时报错:

$ mysql -u root -p
Enter password:
ERROR
2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

尝试去查看mysql.socket文件,发现没有。。

$ which mysql
/usr/local/bin/mysql

然后试试重启mysql:

$ mysql.server start
Starting MySQL
. SUCCESS!

哎 ,说明咱的mysql还能用的嘛,其实内心很担心是不是装了zsh导致的不能启动mysql。。

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ;
or \g.
Your MySQL connection id
is 4
Server version:
5.7.17 Homebrew

哈哈 这么简单就启动了 可以查看各种内容了,还是要多动多练才可以

$ mysql.server start
$ mysql.server restart
$ mysql.server stop
$ mysql.server status
$ mysql
-u root -p
$ sudo mysql
#以root权限登录