修改MySQL参数后Docker部署API出现连接超时问题求助
Docker容器部署API时MySQL连接超时问题求助
我正尝试在Docker容器中部署我的API,原本运行完全正常,但修改MySQL服务器参数后出现了以下问题,恳请各位帮忙分析原因,提前致谢。
#15 [life-tech build 9/9] RUN dotnet-ef database update #15 2.302 Build started... #15 15.06 Build succeeded. #15 15.89 Connection String: Server=server-database;Database=db;Uid=user;Pwd=password;Port=3306;default command timeout=60 #15 31.24 MySqlConnector.MySqlException (0x80004005): Connect Timeout expired. #15 31.24 ---> MySqlConnector.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. #15 31.24 at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, MySqlConnection connection, Int32 startTickCount, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 432 #15 31.24 at MySqlConnector.Core.ConnectionPool.ConnectSessionAsync(MySqlConnection connection, String logMessage, Int32 startTickCount, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 363 #15 31.24 at MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, Int32 startTickCount, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 94 #15 31.24 at MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, Int32 startTickCount, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 124 #15 31.24 at MySqlConnector.MySqlConnection.CreateSessionAsync(ConnectionPool pool, Int32 startTickCount, Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 911 #15 31.24 at MySqlConnector.MySqlConnection.CreateSessionAsync(ConnectionPool pool, Int32 startTickCount, Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 933
本地环境下运行完全正常:
PM> update-database Build started... Build succeeded. Connection String: Server=xxxxxxx;Database=xxxxxx;Uid=xxxxxx;Pwd=xxxxxxxxxxx;Port=3306 Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 6.0.0 initialized 'DbContext' using provider 'Pomelo.EntityFrameworkCore.MySql:6.0.0' with options: ServerVersion 8.0.35-mysql Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (217ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='xxxxxxx' AND TABLE_NAME='__EFMigrationsHistory'; Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (180ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='xxxxxxx' AND TABLE_NAME='__EFMigrationsHistory'; Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (185ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT `MigrationId`, `ProductVersion` FROM `__EFMigrationsHistory` ORDER BY `MigrationId`; Microsoft.EntityFrameworkCore.Migrations[20405] No migrations were applied. The database is already up to date. No migrations were applied. The database is already up to date. Done. PM>
建议可以尝试建立连接并运行一些测试查询。
内容的提问来源于stack exchange,提问作者Raudel Chavez Arroyo
相关产品推荐
相关产品推荐

