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

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

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


当前回答

我曾经遇到过这个问题,并通过安装mysql-server解决了它,所以请确保您已经安装了mysql-server,而不是mysql-client或其他东西。

这个错误意味着文件/var/run/mysqld/mysqld.Sock不存在,如果你没有安装mysql-server,那么这个文件就不存在。在这种情况下,安装它

sudo apt-get install mysql-server

但是如果mysql-server已经安装并且正在运行,那么您需要检查配置文件。

配置文件如下:

/etc/my.cnf
/etc/mysql/my.cnf
/var/lib/mysql/my.cnf

在/etc/my.cnf目录下,套接字文件配置可能是/tmp/mysql。在/etc/mysql/my.cnf中,套接字文件配置可能是/var/run/mysqld/mysqld.sock。因此,删除或重命名/etc/mysql/my.cnf,让mysql使用/etc/my.cnf,那么问题就可以解决了。

其他回答

可能是配置文件有问题。我也遇到过类似的问题,但我在网上找不到解决方案。我注意到我有两个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。

现在有用了……

我已经使用Homebrew在Mac OS X上安装MariaDB 10.1.16教程来解决这个问题。

但是不要忘记杀死或卸载MariaDB的旧安装。

试试这个:

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

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

telnet 127.0.0.1 3306 

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

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.

我也面临着同样的问题,如果你的mysql服务器默认不运行,它会在一些sec后再次停止,所以你再次运行($ sudo service mysql start)命令,你可以改变,如果知道。

对于那个use命令

$ sudo service mysql start   

(如果需要,请输入用户密码,因为我们使用sudo) 然后运行

$ sudo mysql -u root -p          (put user password if required )

现在你有了数据库