“ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Posted

技术标签:

【中文标题】“ERROR 2002 (HY000): Can\'t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock\' (2)” 在 aws linux (centos) 上得到这个【英文标题】:"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)" getting this on aws linux (centos)“ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)” 在 aws linux (centos) 上得到这个 【发布时间】:2017-07-03 15:57:05 【问题描述】:

我第一次尝试在运行以下命令的 aws linux 实例上安装 mysql

sudo yum install mysql-server
sudo mysql_secure_installation

当我运行第二个命令时,我得到了

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Enter current password for root (enter for none): 

我什至没有设置我的根密码。我应该如何输入我一开始没有设置的密码?

【问题讨论】:

我认为之前这台机器上安装了mysql,但没有完全删除 试试这个zyxware.com/articles/5098/… 一个隐藏文件.mysql_secret 将在安装它的用户的主目录下创建。这将包含您用于更改密码的默认密码。 请查看此帖子:***.com/questions/19658891/… @sprksh 已经这样做了。即使重新安装“输入当前密码”后仍然得到完全相同的东西 【参考方案1】:

----列出已安装的mysql

sudo yum list installed | grep mysql

----全部删除

sudo yum remove mysql-client mysql-server mysql-common mysql-devel

手动删除一些配置文件:

sudo rm -rf /var/lib/mysql/
sudo rm -rf /etc/my.cnf

尝试重新安装

sudo yum install mysql mysql-server

获取自动生成的密码

sudo grep 'temporary password' /var/log/mysqld.log

mysql -uroot -p 

使用自动生成密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

希望它能解决你的问题。

https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/linux-installation-yum-repo.html

【讨论】:

我按照您的确切指示删除了所有这些,但很抱歉没有奏效。我尝试将它安装在另一个具有 ubuntu 系统的 ec2 实例上。在安装过程中,系统会提示我们“为 sql 设置 root 密码”。我不知道 Centos 系统出了什么问题。无论如何,谢谢。 @user3576036 实际上 centos 在安装步骤后创建一个自动生成的密码尝试 sudo grep 'temporary password' /var/log/mysqld.log 你会得到密码。现在您可以使用所需的 ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass' 来更改您的密码;

以上是关于“ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' 的主要内容,如果未能解决你的问题,请参考以下文章

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) on Mac

FreeBSD ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/var/run/mysqld/mysqld.sock'

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when I

尝试了一切仍然得到 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (

尝试了一切仍然得到 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (