亲测有效,解决The server quit without updating PID file和Can 't connect to local MySQL server through socket

一、登陆mysql的时候报错

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

出现这个错误,是因为MySQL并没有启动,为了验证这个猜测,可以打开活动监视器,搜索mysqld,是无法搜到的。因为我自己是解决了问题后截图的,所以搜索的时候,mysqld进程已经启动了。

亲测有效,解决The server quit without updating PID file和Can 't connect to local MySQL server through socket_第1张图片

或者输入命令查看 mysql.server status

$ mysql.server status
/usr/local/mysql/support-files/mysql.server: line 365: pidof: command not found
 ERROR! MySQL is not running

可以发现,MySQL没有运行。既然MySQL没有运行,那么我们肯定要启动MySQL。

二、MySQL启动也报错

$mysql.server start
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/XXXX.local.pid).

启动报错了,会不会是权限不够?于是先更改 /usr/local/var/mysql的权限

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

权限解决之后,于是用sudo测试一下,重新启动

三、sudo启动

$ sudo mysql.server start
Password:
Starting MySQL
.. SUCCESS! 

意外的发现,MySQL启动成功了,然后再登陆mysql

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

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

总结:Can 't connect to local MySQL server through socket这个问题是由于MySQL没有启动导致的;The server quit without updating PID file是由于权限问题,解决了权限问题,第一个问题也迎刃而解。

当然由于环境配置不一样,安装方式不一样,解决方法会有些差异,但是引起问题的原因应该是一样的。我是Mac,homebrew安装的mysql,通过此方法,成功解决了问题。

参考stackoverflow上的资料:

MySql server startup error 'The server quit without updating PID file '

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

 

你可能感兴趣的:(mysql,The,server,quit,without,updati,Can,'t,connect,to,local,MySQL,Mac,homebrew)