我在Ubuntu 12.04 LTS (Precise穿山甲)上安装了LAMP,然后在phpMyAdmin上设置根密码。我忘记密码了,现在无法登录。当我试图通过终端更改密码时,我得到:

错误2002 (HY000):无法通过套接字连接到本地MySQL服务器 ' / var /运行/ mysqld / mysqld。袜子”(2)

我该如何解决这个问题?我无法打开LAMP,卸载它或重新安装它。


当前回答

检查你是否拥有正确的权限:

sudo chmod 755 /var/lib/mysql/mysql

我也有同样的问题,这个方法对我很有效。这样做之后,我就可以启动MySQL了。

其他回答

如果您的server/db工作正常,突然出现这个问题,那么只需重新启动您的db服务器。 对于Centos,我使用以下命令和我的问题“连接拒绝”“无法通过套接字连接到本地mysql”修复

sudo systemctl start mysqld

您的mysql服务器可能没有运行。输入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.

我不能解释,但在kubuntu 12.04.2之后

Sudo apt-get autoremove linux-headers-3.2.0-37 linux-headers-3.2.0-37-generic

它开始起作用了

首先,尝试重新启动它

停止mysql服务

启动mysql服务

如果以上还不能解决问题,那就走吧……

完全卸载MySQL

sudo apt-get remove --purge mysql\*

重新安装它

sudo apt install mysql-server mysql-client

测试它是否运行

sudo mysql

安装php驱动程序

sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-cgi php7.4-cli php7.4-common

你可以用php7替换php7.4。X或php8.0.12或更高版本 非常好!

❗️小心,如果没有保存,您将丢失数据。如果可能的话,请备份您的数据。