ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
MySQL数据库多次输入密码错误再登陆或者不输入密码会提示如下错误信息,如下图:

同样的如果登陆是输入密码错误也会提示这个信息,只不过后面的NO变为YES。这个都是密码错误导致的,如下图所示:

好在MySQL提供了跳过验证的登陆方式,我们可以先使用这个方式登陆重新设置root密码,然后再转回正常登陆模式,方法如下:
1、找到配置文件,有些系统的是在/etc路径下的my.cnf,小编的配置文件的路径为/etc/mysql/mysql.conf.d,根据自己的实际情况,如下图所示:

2、编辑该文件,在提示中输入E进行编辑,如下图所示:


3、输入i,进入插入模式,在[mysqld]字段下插入skip-grant-tables,如下图所示:

4、按键盘上的Esc,退出插入模式,输入:wq,按回车键保存并退出,如下图所示:

5、重启MySQL数据库,如下图所示:

6、使用mysql指令进入MySQL数据库,进行密码重置,如下图所示:

7、按照第2、3步骤,将原来添加的skip-grant-table删除,保存退出,如下图所示:

8、再次重启MySQL数据库,如下图所示:

按照上述步骤修改完之后,就可以正常登陆,如下图所示:

另外如果输入mysql指令时,进入不了数据库,而是提示如下错误,如下图所示:

这是因为停止了MySQL服务,使用指令sudo /etc/init.d/mysql start启动服务即可。
网友评论