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

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

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


当前回答

我以前在Kubuntu 20.04中遇到过这个问题。我的解决办法就是跑:

sudo dpkg --configure -a

原因是dpkg崩溃了。

我以前也遇到过这个问题,我通过跑步解决了它:

sudo /etc/init.d/mysql start

我想服务停止了。

其他回答

我也有这个问题,但这些答案都帮不了我。问题是不同的,但错误是由OP描述的。

我检查了MySQL的日志在/var/log/mysql,我看到了这个:

150309  5:03:19 [ERROR] /usr/sbin/mysqld: unknown variable   'lower_case_tables_names=1'

我打开/etc/mysql/my.cnf文件并注释掉#这一行。在此之后,我能够连接到数据库。

说实话,我不知道问题出在哪里。由于维护,linode服务器计划重新启动,这个错误突然出现。

我也面临着同样的问题,如果你的mysql服务器默认不运行,它会在一些sec后再次停止,所以你再次运行($ sudo service mysql start)命令,你可以改变,如果知道。

对于那个use命令

$ sudo service mysql start   

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

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

现在你有了数据库

我曾经遇到过这个问题,并通过安装mysql-server解决了它,所以请确保您已经安装了mysql-server,而不是mysql-client或其他东西。

这个错误意味着文件/var/run/mysqld/mysqld.Sock不存在,如果你没有安装mysql-server,那么这个文件就不存在。在这种情况下,安装它

sudo apt-get install mysql-server

但是如果mysql-server已经安装并且正在运行,那么您需要检查配置文件。

配置文件如下:

/etc/my.cnf
/etc/mysql/my.cnf
/var/lib/mysql/my.cnf

在/etc/my.cnf目录下,套接字文件配置可能是/tmp/mysql。在/etc/mysql/my.cnf中,套接字文件配置可能是/var/run/mysqld/mysqld.sock。因此,删除或重命名/etc/mysql/my.cnf,让mysql使用/etc/my.cnf,那么问题就可以解决了。

我看到所有这些答案,但没有一个提供重置密码的选项,没有接受的答案。实际的问题是他忘记了密码,所以他需要重置,而不是像大多数答案所暗示的那样,看看它是否正在运行(安装与否)。


重置密码

遵循以下步骤(如果你真的忘记了密码,这可能会有帮助,你可以随时尝试,即使你现在没有这种情况):

Stop mysql sudo /etc/init.d/mysql stop Or for other distribution versions: sudo /etc/init.d/mysqld stop Start MySQL in safe mode sudo mysqld_safe --skip-grant-tables & Log into MySQL using root mysql -u root Select the MySQL database to use use mysql; Reset the password -- MySQL version < 5.7 update user set password=PASSWORD("mynewpassword") where User='root'; -- MySQL 5.7, mysql.user table "password" field -> "authentication_string" update user set authentication_string=password('mynewpassword') where user='root'; Flush the privileges flush privileges; Restart the server quit Stop and start the server again Ubuntu and Debian: sudo /etc/init.d/mysql stop ... sudo /etc/init.d/mysql start

在CentOS、Fedora和RHEL上:

    sudo /etc/init.d/mysqld stop
    ...
    sudo /etc/init.d/mysqld start

使用新密码登录 Mysql -u root -p 输入新密码,再次享受您的服务器,就像什么都没有发生一样

这是从重置MySQL根密码。

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

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