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

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

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


当前回答

对我来说是:

打开/etc/mysql/my.cnf或/etc/my.cnf,搜索“bind-address”。结果是127.0.0.1。我将其转换为localhost,因此行结果应该是'bind-address = localhost'。

否则,你应该使用bind-address指令中存在的IP地址运行你的MySQL服务器,即MySQL -h 127.0.0.1。

其他回答

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

我能够连接到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)

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.

而不是使用localhost:

mysql -u myuser -pmypassword -h localhost mydatabase

使用127.0.0.1

mysql -u myuser -pmypassword -h 127.0.0.1 mydatabase

(注意,-p和mpassword之间没有空格)

享受:)

检查my.conf (/etc/mysql/my.cnf),看看bind-address是否设置为127.0.0.1。

如果不是,这可能会导致此问题。

将/opt/lampp/etc/my.cnf文件复制到/etc/mysql/my.cnf

在终端类型中:

mysql -u root

你会得到mysql>提示:

mysql> Update mysql.user set Password=PASSWORD('your_password') where user='root';

mysql> FLUSH PRIVILEGES;