MySqlException-用户被拒绝访问:MySQL,ASP.NET Core 3

时间:2019-05-06 23:41:34

标签: c# mysql asp.net-core .net-core asp.net-core-2.1

我正在使用NET Core 2.1MySQL并已安装MySql.Data。 这是appsettings.json

"ConnectionStrings": {
     "DefaultConnectionString": 
        "server=localhost;port=3306;database=database_name;user=root;password=password"
}

还有Startup.cs -> ConfigureServices

services.AddDbContext<CardsContext>(options =>

  options.UseMySQL(Configuration.GetConnectionString("DefaultConnectionString")));

整个应用都是简单的脚手架CRUD应用,但是当我尝试访问某些GET之类的/api/persons/5路由时,出现此错误:

  

处理请求时发生未处理的异常。   MySqlException:拒绝用户'root'@'localhost'的访问(使用密码:是)   MySql.Data.MySqlClient.MySqlStream.ReadPacket()

     

MySqlException:使用方法'mysql_native_password'对用户'root'的主机'localhost'进行身份验证失败,并显示以下消息:用户'card_root'@'localhost'的访问被拒绝(使用密码:是)   MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)

我确定这是配置,因为我可以使用相同的用户/通过/数据库/端口/主机连接PHP

1 个答案:

答案 0 :(得分:0)

检查连接字符串中的密码!如果正确的话:

  1. 在phpmyadmin的document.write(environment.variable)中创建一个新用户!

  2. 确保将User Accounts定义为Host Name

  3. 声明一个清晰的密码,以便以后使用。

  4. 检查全局特权!