mysql Access denied for user 'root'@'localhost' (using password: YES
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
以上是关于mysql Access denied for user 'root'@'localhost' (using password: YES的主要内容,如果未能解决你的问题,请参考以下文章
java访问数据库被拒绝,不能连接数据库ERROR 1045 (28000): Access denied for user 'root'@'localhost' (u
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
mysql错误 Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES)
mariadb mysql -u root -p 显示Access denied解决办法