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

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

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


当前回答

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

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

其他回答

在/etc/mysql/my.cnf中,检查最后一行是:

!includedir /etc/mysql/conf.d/

我不得不说:

sudo /etc/init.d/mysqld start

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

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服务器默认不运行,它会在一些sec后再次停止,所以你再次运行($ sudo service mysql start)命令,你可以改变,如果知道。

对于那个use命令

$ sudo service mysql start   

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

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

现在你有了数据库

在我的情况下,我错过了mysql服务器。所以在通过sudo apt-get install mysql-server安装它之后,我又可以连接了。