mysql新建用户 error 1045_MySQL创建新用户时登录出错(ERROR 1045)

在MySQL中我用如下语句创建了一个新的用户

CREATE USER 'KevinYin'@'%' IDENTIFIED BY 'password'

GRANT ALL PRIVILEGES ON *.* TO 'KevinYin'@‘%'FLUSH PRIVILEGES;

紧接着我用新创建的用户进行登录:

mysql -u KevinYin -pmySQL报错,信息如下:

ERROR 1045 (28000): Access denied for user 'KevinYin'@'localhost' (using password: YES)但是,我如果这样登录:

mysql -u KevinYin 即可正常登录

不清楚是什么造成这样的故障的,在网上找了一阵发现了原因:

“When multiple matches are possible, the server must determine which of them to use. It resolves this issue as follows: (...)

When a client attempts to connect, the server looks through the rows [of table mysql.user] in sorted order.

The server uses the first row that matches the client host name and user name.

(...) The server uses sorting rules that order rows with the most-specific Host values first. Literal host names [such as 'localhost'] and IP addresses are the most specific.”这是由系统中的匿名用户及MySQL的认证机制造成的。解决办法就是删除系统中的匿名用户:

DROP USER ''@'localhost'即可解决。

详情参考:MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost'

(using password: YES)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值