首页 > 代码库 > mysql Access denied for user 'root'@'localhost' (using password: YES)

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工具一闪而过,方法参见这里


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