【发布时间】:2018-07-15 03:02:10
【问题描述】:
我正在尝试对我的 AWS Aurora MySql RDS 集群运行 dotnet ef database update CLI 命令。仅出于测试目的,我对连接字符串进行了硬编码,以消除配置加载的问题。
当我运行update 命令时,出现以下错误:
使用连接到服务器“some-rds-cluster.abcdefg.us-east-2.rds.amazonaws.com”上的数据库“”时出错。
MySql.Data.MySqlClient.MySqlException (0x80004005):用户 'bobby'@'555.555.555.555' 的访问被拒绝(使用密码:YES)
在 C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 333 中的 MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancelToken)
我的ConfigureServices 方法如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.AddDbContextPool<AccountContext>(options =>
{
options.UseMySql("server=a-random-cluster.foobar.us-east-2.rds.amazonaws.com;database=SomeDbHere;user=abcdefg;password=abcdefg", contextOptionsBuilder =>
{
contextOptionsBuilder.ServerVersion(new Version(5, 7, 12), ServerType.MySql);
});
});
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
我可以在本地机器上使用 MySql Workbench 连接到集群;来自同一台机器的update CLI 命令虽然失败了。附加到 RDS 的安全组允许来自我的 IP 地址的流量连接(因此 MySql Workbench 连接的原因)。为了让 CLI 更新表,我需要对 EF Core 和 Pomelo.EntityFrameworkCore.MySql 做些什么? Aurora 是否支持 EF Core 为更新数据模型而需要执行的操作,例如出于某种原因使用不同的端口号?
我注意到错误说“使用与数据库的连接''',我无法判断它是否故意将数据库名称留空或者这是否是问题的一部分。数据库是在迁移和连接字符串中指定的不过,所以我会假设他们不使用数据库名称,因为在 MySql 中它不是 Db,而是“模式”。
我正在运行 aspnetcore 2.1.0 和 EF core 2.1.0
我从下面的实体和上下文中生成了迁移。
public partial class InitialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "SomeDbHere");
migrationBuilder.CreateTable(
name: "Users",
schema: "SomeDbHere",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation(
"MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn),
Username = table.Column<string>(nullable: true),
CognitoId = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users",
schema: "SomeDbHere");
}
}
【问题讨论】:
标签: c# mysql entity-framework amazon-web-services amazon-aurora