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

在自己搭建的虚拟机上运行曾经安装的mysql,报如下信息:

[root@localhost mysql]# mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

查找该文件也是没有找到

[root@localhost mysql]# find / -name mysql.sock

编辑/etc/my.cnf文件
在这里插入图片描述

重启服务:

[root@localhost tmp]# service mysql restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL...... SUCCESS! 

报了一个PID找不到,又说启动成功,有点懵,连接下

[root@localhost tmp]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

先停止服务

[root@localhost tmp]# service mysql stop
Shutting down MySQL.. SUCCESS! 

使用safe模式

[root@localhost tmp]# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

在上面执行的情况下,手动输入下面四句,按ctrl+z结束输入

usr/local/mysql/data
mysql -u root
update mysql.user set authentication_string=PASSWORD('huangbaokang') where user='root';
flush privileges;

在这里插入图片描述

经过这样之后就可以以root 密码为huangbaokang登录mysql了。

猜你喜欢

转载自blog.csdn.net/huangbaokang/article/details/84788568
今日推荐