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工具输入password后一闪而过问题同一时候解决。

重新启动之后又訪问不了,继续上面的思路改动:



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



还有一password相关问题(调试机放几天后就没法远程訪问了,rootpassword被修改,不明原因):

 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;


posted on 2016-02-21 18:25  gcczhongduan  阅读(1529)  评论(0编辑  收藏  举报