mysql root不能本机登录_MySQL 5.7 root用户无法本机登录数据库

这两天遇到了一个令人头大的一个问题,在安装MySQL5.7后,出现了MySQL默认的root用户无法在虚拟机本机上登录数据库:

[[email protected] bin]#mysql -uroot -p

Enter password:

ERROR1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

提示拒绝了localhost上的root用户的使用密码登录。

令人不得其解,刚刚安装的MySQL怎么就登录不上了呢,密码是正确的,在物理机上通过navicat连接数据库也可以正常连接:

46b4f3b494c75f73b39d5a35a672bf47.png

证明密码和用户名是正确的,怎么会连接不上了呢?

通过百度后,尝试使用不使用密码登录的方式,修改root用户的密码后再进行登录,依然存在该问题,证明不是密码的问题;

查询mysql.user表:

select Host,user,authentication_string from mysql.`user`;

00ecfa19a7d9d86f15b542f2516964a9.png

可以看到root用户的允许host被我在安装时修改为‘192.168.137.%’,这直接导致mysql在我使用root用户在localhost上登录时禁止登录,解决的方式也很简单,直接修改root用户的Host字段为‘%’就可以解决这个问题。

UPDATE mysql.user set Host = ‘%‘ WHERE user = ‘root‘;

然后再次登录:

[[email protected] bin]#mysql -h127.0.0.1 -uroot -p

Enter password:

Welcome to the MySQL monitor. Commandsendwith ; or \g.

Your MySQL connection id is7Server version:5.7.29MySQL Community Server (GPL)

Copyright (c)2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type ‘help;‘ or ‘\h‘forhelp. Type ‘\c‘ to clear the current input statement.

mysql>

就可以使用啦~

cd5e012b16d01e04796f83c4c4ea2341.gif

原文:https://www.cnblogs.com/xfyy-2020/p/12825569.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值