我在Ubuntu 12.04 LTS (Precise穿山甲)上安装了LAMP,然后在phpMyAdmin上设置根密码。我忘记密码了,现在无法登录。当我试图通过终端更改密码时,我得到:
错误2002 (HY000):无法通过套接字连接到本地MySQL服务器 ' / var /运行/ mysqld / mysqld。袜子”(2)
我该如何解决这个问题?我无法打开LAMP,卸载它或重新安装它。
我在Ubuntu 12.04 LTS (Precise穿山甲)上安装了LAMP,然后在phpMyAdmin上设置根密码。我忘记密码了,现在无法登录。当我试图通过终端更改密码时,我得到:
错误2002 (HY000):无法通过套接字连接到本地MySQL服务器 ' / var /运行/ mysqld / mysqld。袜子”(2)
我该如何解决这个问题?我无法打开LAMP,卸载它或重新安装它。
当前回答
我只是在不得不重新启动生产服务器后遇到了同样的问题。我正在DigitalOcean液滴上运行Debian 8.1 (Jessie)。
这是我解决问题的方法:
检查文件/var/run/mysqld/mysqld.袜子的存在。如果没有,手动创建它,输入touch /var/run/mysqld/mysqld.袜子(这是我必须做的)。 所以MySQL进程可以使用这个文件。通过输入chown mysql /var/run/mysqld/mysqld.sock更改该文件的所有权。 执行完“2”后,输入service MySQL restart或/etc/init.重新启动MySQL服务d / mysql重启。
经过上述步骤后,我的问题得到了解决。我很少遇到这种问题,可能有更好的方法,所以如果需要,请务必提供建设性的反馈:)。
其他回答
如果您的Linux机器上安装了XAMPP,请尝试将my.cnf文件从/opt/lampp/etc/my.cnf复制到/etc/my.cnf
然后,再次运行mysql -u root…现在您应该有了正确的套接字,并且能够运行MySQL客户端。
This error can also occur if you try to change the directory where the database is stored, but imput the wrong directory in the configuration file (like a typo in the second drive as D instead of the accurate D_). Instead of telling you the typo directory does not exist, it will tell you that you lack permission to access it (leading you to try to change the permissions for the typo directory, which it will let you do). So if you get this error while changing directories, double check the configuration file and make sure you don't have a typo.
如果您的server/db工作正常,突然出现这个问题,那么只需重新启动您的db服务器。 对于Centos,我使用以下命令和我的问题“连接拒绝”“无法通过套接字连接到本地mysql”修复
sudo systemctl start mysqld
发生此问题是因为MySQL服务器未启动。使用以下命令检查活动状态。
service mysql status
如果active状态为stop,请尝试启动MySQL服务器。
service mysql start
检查my.conf (/etc/mysql/my.cnf),看看bind-address是否设置为127.0.0.1。
如果不是,这可能会导致此问题。