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

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

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


当前回答

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

ps -ef | grep mysql
kill [the id]

然后我再次启动服务器:

sudo /etc/init.d/mysql restart

但是start也同样有效:

sudo /etc/init.d/mysql start

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

其他回答

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

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

对我来说,更新解决了这个问题:

在Ubuntu上:

sudo apt-get update
sudo apt-get upgrade

CentOS:

sudo yum update

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.server start

如果你在mac上使用brew安装mysql,只需使用:

brew services start mysql

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

sudo chmod 755 /var/lib/mysql/mysql

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