[英]'dotnet ef database update' command gives error: Host 'host.docker.internal' is not allowed to connect to this MySQL server
Hi StackOverflow Community,嗨 StackOverflow 社区,
I have a code first application in .netcore 3.0 that connects to SQL Server in the back-end.我在 .netcore 3.0 中有一个代码优先应用程序,它连接到后端的 SQL 服务器。 I am trying to migrate my existing SQL Server Database to MySQL.
我正在尝试将现有的 SQL 服务器数据库迁移到 MySQL。
dotnet ef migrations add InitialCreation command worked well. dotnet ef migrations add InitialCreation命令运行良好。
However,然而,
dotnet ef database update command gives an error: dotnet ef 数据库更新命令给出错误:
Can anyone explain what is going on and why host.docker.internal is not allowed to connect?谁能解释发生了什么以及为什么host.docker.internal不允许连接?
This is the Migrations reference document and here is the error: 这是迁移参考文档,这是错误:
MySql.Data.MySqlClient.MySqlException (0x80004005): Host 'host.docker.internal' is not allowed to connect to this MySQL server
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MySql.Data.EntityFrameworkCore.MySQLDatabaseCreator.<>c__DisplayClass18_0.<Exists>b__0(DateTime giveUp)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
at MySql.Data.EntityFrameworkCore.Storage.Internal.MySQLExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation, Func`2 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation)
at MySql.Data.EntityFrameworkCore.MySQLDatabaseCreator.Exists(Boolean retryOnNotExists)
at MySql.Data.EntityFrameworkCore.MySQLDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Host 'host.docker.internal' is not allowed to connect to this MySQL server
It's look like you try to use a MySQL user that is not allowed to connect from this hostname.看起来您尝试使用不允许从此主机名连接的 MySQL 用户。
On MySQL, when you create a user, you specify a username and a host user@host
.在 MySQL 上,当您创建用户时,您指定用户名和主机
user@host
。 If the hostname doesn't fit, the user can't connect to the server.如果主机名不合适,则用户无法连接到服务器。
If you want a user that could connect from anywhere, you need to use the hostname %
like 'username'@'%'
.如果您想要一个可以从任何地方连接的用户,您需要使用主机名
%
,例如'username'@'%'
。
For more information, you can read the MySQL doc about account names: https://dev.mysql.com/doc/refman/8.0/en/account-names.html For more information, you can read the MySQL doc about account names: https://dev.mysql.com/doc/refman/8.0/en/account-names.html
You can check the user list with this query:您可以使用以下查询检查用户列表:
mysql> select Host, User from mysql.user;
+-----------+---------------+
| Host | User |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| % | julien |
+-----------+---------------+
4 rows in set (0.00 sec)
On this example, the user julien
can connect to MySQL from anywhere but user root
could connect to mysql only from localhost.在此示例中,用户
julien
可以从任何地方连接到 MySQL,但用户root
只能从 localhost 连接到 mysql。
In your case, the connection come from host.docker.internal
, the hostname of your host from the point of vue of the MySQL container.在您的情况下,连接来自
host.docker.internal
,您的主机的主机名来自 MySQL 容器的 vue 点。 The MySQL container doesn't have the some localhost
than your host or than an another container. MySQL 容器没有比您的主机或另一个容器更多的
localhost
主机。
If the user used for the connection is not authorized in MySQL to connect from host.docker.internal
or from anywhere, MySQL will reject the connection with the error Host 'host.docker.internal' is not allowed to connect to this MySQL server
If the user used for the connection is not authorized in MySQL to connect from
host.docker.internal
or from anywhere, MySQL will reject the connection with the error Host 'host.docker.internal' is not allowed to connect to this MySQL server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.