暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

登录MySQL时出现ERROR 2002 (HY000)

西邮Linux兴趣小组 2021-05-16
2869

登录MySQL时出现ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 的解决方法

解决方案:


「成员意见」:
1:helight:客户端链接默认的链接socket 文件位置不一样,你看看/tmp/mysql.sock
让后做个软链接。
2:问题已经解决,但是不是用的上面的方法。是我自己的原因,将/etc/mysql/my.cnf里面的socket修改到/home下了,但/home下面没有那个文件。
3:登录不上肯定有日志, 所以问问题的时候一定要把错误日志贴上来,方便别人分析问题。
4:这种error是你的mysql服务没有启动,因此无法连接mysqld.sock,而mysqld.sock是服务启动时生成的,当你kill掉mysql后,这个sock文件也就不存在了;

首先ps查看mysql进程是否存在,再netstat查看3306端口是否监听,确认下mysql是否启动,如果没有启动,执行启动服务即可!


「网络结果」:
1:Kadrus:try'sudo mysqladmin password newpassword', type a new pass... and then 'sudo mysql -u root -p', good luck.
译:试试'sudo mysqladmin password newpassword',键入一个新密码……然后 'sudo mysql -u root -p',祝你好运。
2:sevenearths:I got the following:
root@localhost:/home/arthur# mysqladmin password newpassword
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
root@localhost:/home/arthur#
译:我得到了这个结果:
root@localhost:/home/arthur# mysqladmin password newpassword
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
root@localhost:/home/arthur#
3:dwhitney67:This may seem silly, but have you verified that the MySQL server is running?
Verify using 'ps -ef | grep mysql'. You should see something like:
$ ps -ef |grep mysql
root      5325     1  0 13:09 ?        00:00:00 bin/sh usr/bin/mysqld_safe
mysql     5413  5325  0 13:09 ?        00:00:00 usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
root      5415  5325  0 13:09 ?        00:00:00 logger -p daemon.err -t mysqld_safe -i -t mysqld
译:我这样问也许比较傻,但是……你确认你的MySQL服务器处于运行的状态吗?
用'ps -ef | grep mysql'来确认一下。如果它处于运行中,你应该会看见类似以下结果:
$ ps -ef |grep mysql
root      5325     1  0 13:09 ?        00:00:00 bin/sh usr/bin/mysqld_safe
mysql     5413  5325  0 13:09 ?        00:00:00 usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
root      5415  5325  0 13:09 ?        00:00:00 logger -p daemon.err -t mysqld_safe -i -t mysqld
4:sevenearths:Not to sure what I'm looking for, but this is what I get:
arthur@localhost:~$ ps -ef | grep mysql
arthur    6946  6928  0 22:39 pts/0    00:00:00 grep mysql
arthur@localhost:~$
译:我不确定我需要找的是什么,但我得到了如下结果:
arthur@localhost:~$ ps -ef | grep mysql
arthur    6946  6928  0 22:39 pts/0    00:00:00 grep mysql
arthur@localhost:~$
5:dwhitney67:Your mysql server is not running!
I don't have my Ubuntu system available at this moment, but I believe if you navigate into the System->Administration pull-down, there is a menu option to control 'services' or something to that effect.

文章转载自西邮Linux兴趣小组,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论