二维码

1、安装完MySQL5.7之后,使用mysql -u root -p登录MySQL时报错:

[root@localhost bin]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

2、百度搜了很多解决方法,都是使用安全模式启动数据:

service mysqld stop                                              #首先关闭mysql服务
mysqld_safe --user=root --skip-grant-tables --skip-networking &  #然后使用mysqld_safe跳过权限方式启动
mysql                                                            #然后直接登录,跳过密码验证
update mysql.user set password=password('123456') where user='root';    #将密码设置为123456

3、但是在安装目录/usr/bin/下根本找不到mysqld_safe这个文件,所以这个方法无效。

4、找了大半天,终于找到一个介绍,skip-grant-tables这个是配置参数,可以放在mysql配置文件里面修改,然后把这个配置参数放到/etc/my.cnf文件里面。

CentOS 7安装 MySQL5.7之后,登录提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passw

5、添加进去后重启mysql服务,就可以正常登进去mysql数据库了;

CentOS 7安装 MySQL5.7之后,登录提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passw

 

6、但是设置密码的时候,输入update mysql.user set password=password('123456') where user='root';发现password字段不存在,突然间心态大崩。

CentOS 7安装 MySQL5.7之后,登录提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passw

7、最后执行select * from mysql.user;命令查看找到user表authentication_string这个列的值与password的只相似,于是将这个字段的值备份一下。

8、执行update mysql.user set authentication_string=password('123456') where user='root';

9、然后退出mysql,执行systemctl restart mysqld.service重启数据库,再次登录,终于解决问题!

CentOS 7安装 MySQL5.7之后,登录提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passw


©著作权归作者所有:来自ZhiKuGroup博客作者没文化的原创作品,如需转载,请注明出处,否则将追究法律责任 来源:ZhiKuGroup博客,欢迎分享。

评论专区
  • 昵 称必填
  • 邮 箱选填
  • 网 址选填
◎已有 0 人评论
搜索
作者介绍
30天热门
×
×
本站会员尊享VIP特权,现在就加入我们吧!登录注册×
»
会员登录
新用户注册
×
会员注册
已有账号登录
×