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

前提:Mac hombrew 安装mysal

debug记录:

起因因为重启了电脑,然后登陆账号时发现mysql出现下列问题

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

分析:报错说在tmp文件下没有找到mysql.sock文件。由于连接服务器是通过socket通信,所以用mysql.server start 查看是否已经启动mysql server

如果能够直接启动成功:

Starting MySQL
. SUCCESS! 

下一步登录账号密码就成功了。

(本来电脑重启只是关闭了server,启动就好了,看网上各种文章反而越调越乱QTQ,此处省略重装过程的弯路,根据亲身测试,宁愿修bug,也别重装mysql,没个两三天卸不干净)

如果出现以下错误

ERROR! The server quit without updating PID file (/usr/local/var/mysql/Sheryl.pid).

apple@Sheryl bin % mysql.server start                       
Starting MySQL
./usr/local/Cellar/[email protected]/5.7.37/bin/mysqld_safe: line 144: /usr/local/var/mysql/Sheryl.err: Permission denied
/usr/local/Cellar/[email protected]/5.7.37/bin/mysqld_safe: line 144: /usr/local/var/mysql/Sheryl.err: Permission denied
/usr/local/Cellar/[email protected]/5.7.37/bin/mysqld_safe: line 198: /usr/local/var/mysql/Sheryl.err: Permission denied
/usr/local/Cellar/[email protected]/5.7.37/bin/mysqld_safe: line 144: /usr/local/var/mysql/Sheryl.err: Permission denied
 ERROR! The server quit without updating PID file (/usr/local/var/mysql/Sheryl.pid).

分析是因为权限不够的问题,加上sudo,可以启动成功!!!

apple@Sheryl bin % sudo mysql.server start
Starting MySQL
. SUCCESS! 
apple@Sheryl bin % sudo mysql.server status
 SUCCESS! MySQL running (7802)

mysql.server的其他命令也要加上sudo,否则会出现明明已经启动,但是却显示没有运行的问题

apple@Sheryl bin % mysql.server status
 ERROR! MySQL is not running, but PID file exists
apple@Sheryl bin % sudo mysql.server status
Password:
 SUCCESS! MySQL running (7802)

mysql命令测试,不能连接,因为重装过,所以using password: NO,一般设置了密码都是YES

ERROR 1045 (28000): Access denied for user ‘apple’@‘localhost’ (using password: NO)

apple@Sheryl bin % mysql -u root -p
ERROR 1045 (28000): Access denied for user 'apple'@'localhost' (using password: NO)

我是通过hombrew安装的mysql,所以选择安装mysql_secure_installation插件来重新设置密码,就可以用密码登录啦.

查看tmp文件下也有mysql.sock,mysql.sock.lock文件,成功连接mysql。

你可能感兴趣的:(那些事,mysql)