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

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

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


当前回答

可能是配置文件有问题。我也遇到过类似的问题,但我在网上找不到解决方案。我注意到我有两个my.cnf文件,一个在/etc/mysql,另一个在/etc。 遵循以下步骤:

使用定位my.cnf在您的计算机上检查my.cnf文件。 如果有两个条目,即/etc/my.cnf和/etc/mysql/my.cnf, 将/etc/mysql/my.cnf重命名为其他内容,例如/etc/mysql/my.cnf.old

尝试再次运行MySQL。

其他回答

如果您的Linux机器上安装了XAMPP,请尝试将my.cnf文件从/opt/lampp/etc/my.cnf复制到/etc/my.cnf

然后,再次运行mysql -u root…现在您应该有了正确的套接字,并且能够运行MySQL客户端。

我在mariadb的termux中遇到了这个问题,它解决了我的问题是以下两行命令-

Pkill MySQL

Mysqld_safe -u root

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.

你检查过LAMPP是否在运行吗?

sudo bash <path>/lampp start

对我来说,路径就是

sudo bash /opt/lampp/lampp start

以我为例,我做了一些研发工作:

我能够连接到MySQL使用

root-debian#mysql -h 127.0.0.1 -u root -p

但是在mysql中-u root -p行不通。

我在my.cnf中没有找到任何绑定地址。所以我注释了参数socket=/var/lib/mysql/mysqld。袜子在我的。cnf导致我登录的问题。

重新启动服务后,一切正常:

root@debian:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.19 MySQL Community Server (GPL)