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

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

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


当前回答

首先,尝试重新启动它

停止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或更高版本 非常好!

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

其他回答

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

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

它开始起作用了

我只是在不得不重新启动生产服务器后遇到了同样的问题。我正在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重启。

经过上述步骤后,我的问题得到了解决。我很少遇到这种问题,可能有更好的方法,所以如果需要,请务必提供建设性的反馈:)。

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.

如果您正在使用Amazon EC2,并且在实例上遇到了这个问题,那么您只需要执行以下操作:

sudo yum install mysql-server
sudo service mysqld restart

Amazon EC2没有安装服务器(只安装了客户端),因此在这种情况下,您需要在实例上安装服务器,然后尝试

 mysql -u root -p

来检验这是否有效。

试试这个:

mysql -h 127.0.0.1 -P 3306 -u root -p <database>

另外(看看它是否在运行):

telnet 127.0.0.1 3306 

可能只是my.cnf文件中的错误配置,在/etc/某处(取决于Linux发行版)。