最新消息:

MySQL 解决 ERROR 2002 (HY000): Can’t connect to local MySQL server

软件 4591浏览

1. 出现问题

修改MySQL配置文件后,重启 mysql,本地登录 mysql

mysql -u root -p

结果报错

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

此时通过添加主机地址可正常访问

mysql -h 127.0.0.1 -u root -p

查看 my.cnf,可以发现问题源头,[client]、[mysqld_safe]、[mysqld] 中均配置了

socket = /var/run/mysqld/mysqld.sock

 

[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql

2. 根目录下搜索 mysqld.sock

find / -name mysqld.sock

如果能找到 mysqld.sock 文件,将my.cnf配置文件中的路径改为 mysqld.sock 文件的路径即可。

3. 重启 mysql

使用如下命令重启 mysql

service mysql stop
service mysql start

问题解决,现在可以正常登录了。

好了,MySQL 解决 ERROR 2002 (HY000): Can’t connect to local MySQL server 就分享到这里,非常感谢你的来访。如果你很喜欢本站,请不要忘记收藏本站,以便下次继续访问;也可以 关注站长微博 随时获取最新动态。你的支持就是我最大的动力!

转载请注明:爱维科斯 » MySQL 解决 ERROR 2002 (HY000): Can’t connect to local MySQL server

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者