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

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

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


当前回答

我认为当你得到错误的时候

ERROR 2002 (HY000):无法通过套接字/var/lib/ MySQL / MySQL .sock连接到本地MySQL服务器

我建议你先检查一下mysql守护进程是否在运行…大多数情况下,默认情况下它不会运行。你可以通过/etc/init.检查d / mysqld的地位。

如果它没有运行,那么先启动它:

.../etc/init.d/mysqld start.

我打赌它会110%有效。

其他回答

您可以首先检查服务是否正在运行,使用:

ps ax | grep mysql

我得到了这样的回答:

6104 pts/0    S      0:00 /bin/sh /usr/bin/mysqld_safe
6431 pts/0    Sl     0:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --pid-file=/var/run/mysqld/m

没有响应意味着服务没有运行,请执行以下操作:

service  mysql start

我通过杀死mysql进程来解决这个问题:

ps -ef | grep mysql
kill [the id]

然后我再次启动服务器:

sudo /etc/init.d/mysql restart

但是start也同样有效:

sudo /etc/init.d/mysql start

然后我以管理员身份登录,就搞定了。

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.

我认为当你得到错误的时候

ERROR 2002 (HY000):无法通过套接字/var/lib/ MySQL / MySQL .sock连接到本地MySQL服务器

我建议你先检查一下mysql守护进程是否在运行…大多数情况下,默认情况下它不会运行。你可以通过/etc/init.检查d / mysqld的地位。

如果它没有运行,那么先启动它:

.../etc/init.d/mysqld start.

我打赌它会110%有效。

在我的情况下,我的问题是,我试图从我的linux终端访问,而不是从我的docker容器与mysql。