mysql Access denied for user 'root'@'localhost' (using password: YES)

【现象说明】

C/S程序远程访问正常,本地访问报以下异常

MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'@'localhost' (using password: YES) ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Access denied for user 'root'@'localhost' (using password: YES)

配置文件如下:

<add name="RemoteConnString" connectionString="Database='mealbooker';Data Source='localhost';User Id='root';Password='123456';charset='gb2312';pooling=true" providerName="MySql.Data.MySqlClient"/>


【分析】

权限问题吧,查看下mysql数据库中的user表


发现localhost下面值为空,于是connection string中的localhost 改为 127.0.0.1,测试通过~~~

【解决】


配置文件中改为localhost,访问数据库正常;同时mysql command line工具输入密码后一闪而过问题同时解决。

重启之后又访问不了,继续上面的思路修改:



另,mysql command line工具一闪而过,方法参见这里


另一个权限相关问题:

Error Code: 1370 execute command denied to user 'root'@'localhost' for routine

使用grant execute on procedure/function dbname.fname TO 'root'@'localhost';



另一密码相关问题(调试机放几天后就没法远程访问了,root密码被改动,不明原因):

 Authentication to host '10.10.123.6' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'@'10.10.123.5' (using password: YES) ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Access denied for user 'root'@'10.10.123.5' (using password: YES)

修改password语句如下:


然后还要给远程用户非配权限

grant all privileges on *.* to 'root'@'%' with grant option;


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值