我正在使用NET Core 2.1
和MySQL
并已安装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
答案 0 :(得分:0)
检查连接字符串中的密码!如果正确的话:
在phpmyadmin的document.write(environment.variable)
中创建一个新用户!
确保将User Accounts
定义为Host Name
!
声明一个清晰的密码,以便以后使用。
检查全局特权!