mysql5.7报错 过期,centos7下mysql5.7修改密码和外部能访问的步骤、讲解和所遇到的那些坑(最全)...

登录mysql报错

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

1、登录安装数据库的机器

输入vi /etc/my.cnf,在该配置文件增加一行 skip-grant-tables,随便什么密码都能登陆

2、重启数据库

service mysqld restart

3、连接数据库

mysql -u root -p随便输入个密码

4、进入数据库mysql

use mysql

61bc6d8f30f05840110785169397fc19.png

5、先查看密码是否过期(user表用于放用户信息)

#password_lifetime=0表示永久有效,password_expired='N'密码未过期

select password_expired,password_last_changed,password_lifetime,authentication_string from user u where u.user='root';

e07c86b9f001d7c2d49be9e63ed36f13.png

6、修改root的密码、有效时间和是否过期,并提交

update user set authentication_string =password('kang') ,password_lifetime=0,password_expired='N' where user='root';

flush privileges;

ceb2cb4045c41485c782af219c4b8042.png

7、再查看(密码已改),再输入exit退出

select password_expired,password_last_changed,password_lifetime,authentication_string from user u where u.user='root';

f5354491bc52fe172cf48b6aa52c0f27.png

8、 输入vi /etc/my.cnf,在该配置文件删掉 skip-grant-tables,使需要正确密码才能登陆

9、重启数据库

service mysqld restart

此时又出现个问题,只有本地才能访问,其他地方访问还是报错

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

这时候就需要设置其他机器也能访问

1、查看root哪些能访问

00f113b8f97197902228e56aad97dd40.png

2、更新其他机器也能访问root, %表示都能访问,localhost表示只有本机能访问

update user set host='%' where user='root';

2c08afb0e22b9f879164a21e2b308e9b.png

--欢迎大家访问我的 个人博客(www.sunkang.com)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值