mysql Can't connect to local MySQL server through socket 问题解决

系统环境:Mac。

操作过程:使用mysql -u{用户名} -p{密码} 失败。

错误信息:

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

原因分析:

1.可能mysql服务停止了。

  mysqld_safe是一个shell 脚本,会调用mysqld启动mysql服务器,并监听服务器。

   如果mysqld进程异常终止,mysqld_safe将自动重启mysqld。

运行

/usr/local/mysql/bin/mysqld_safe &

&为后台启动。

后再次使用:

mysql -u{用户名} -p{密码}

成功!

原文地址:https://www.cnblogs.com/uinique/p/7791938.html