mysql匿名用户引起的Access denied

mysql匿名用户引起的Access denied

场景描述

  • mysql -ujz -p123123 -h 192.168.5.178
    可以正常登陆(192.168.5.178为本机ip)
  • mysql -ujz -p123123
    提示ERROR 1045 (28000): Access denied for user ‘jz’@’localhost’ (using password: YES)

问题分析

  • select host, user, password from mysql.user;
hostuserpassword
%jz*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1
localhost
localhostroot

注意:存在localhost匿名用户,并且无密码

  • 问题存在于mysql的用户匹配问题,通过查阅官方文档

The server uses sorting rules that order rows with the most-specific Host values first. Literal host names and IP addresses are the most specific. (The specificity of a literal IP address is not affected by whether it has a netmask, so 192.168.1.13 and 192.168.1.0/255.255.255.0 are considered equally specific.) The pattern ‘%’ means “any host” and is least specific. The empty string ” also means “any host” but sorts after ‘%’. Rows with the same Host value are ordered with the most-specific User values first (a blank User value means “any user” and is least specific). For rows with equally-specific Host and User values, the order is indeterminate.

这里可以看出@localhost的比jz@%优先级要高,也就是说mysql -ujz在不指定host登录的时候, 匹配到的是@localhost,也就是不需要输入密码即可登录。

问题总结

为了数据的可维护性,不要创建匿名用户,尽量设定详细的host

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值