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)

配置文件如下:


【分析】

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

mysql Access denied for user 'root'@'localhost' (using password: YES)_第1张图片

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

【解决】

mysql Access denied for user 'root'@'localhost' (using password: YES)_第2张图片

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

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

mysql Access denied for user 'root'@'localhost' (using password: YES)_第3张图片


另,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;


你可能感兴趣的:(数据库,问题处理)