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

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

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


当前回答

试试这个:

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

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

telnet 127.0.0.1 3306 

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

其他回答

发生此问题是因为MySQL服务器未启动。使用以下命令检查活动状态。

service mysql status

如果active状态为stop,请尝试启动MySQL服务器。

service mysql start

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

然后,再次运行mysql -u root…现在您应该有了正确的套接字,并且能够运行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.

在Ubuntu 18:10 Linode 1GB Ram中,我遇到了这个错误。在检查了/var/log/mysql/error.log之后,我发现了这个:

[注]InnoDB: innodb_empty_free_list_algorithm由于缓冲池大小较小,修改为legacy。为了使用回退,请将缓冲池至少增加到20MB。

我把我的linode升级到2GB,用sudo mysql重新启动mariadb。接下来运行mysql_secure_admin,但是没有为user-as ususl设置根密码,直到更改根用户使用mysql_native_password插件。 不确定,但似乎袜子是创建的,但由于我的VPS内存不足,服务器关闭了。

一个建议:总是问MySQL问题是什么。在我的例子中,减少/var/log/mysql/error.log,看到这个:

2015-07-28 12:01:48 23224 [ERROR] /usr/sbin/mysqld: unknown variable 'log_slow_queries=/var/log/mysql/mysql-slow.log'
2015-07-28 12:01:48 23224 [ERROR] Aborting

它在抱怨,因为我在my.cnf中未注释此选项,但在注释此选项后,它启动时没有任何问题。