由于未知套接字错误,无法连接到 Google Cloud Run 上的 MySQL
我正在 Cloud Run 上运行 .NET 6 服务并尝试使用内置套接字进行连接。我的实例名称是 project-id:region:instance-name
,构建连接的代码如下...
var builder = new MySqlConnectionStringBuilder
{
SslMode = IsCloud ? MySqlSslMode.None : MySqlSslMode.Required,
Server = IsCloud ? $"/cloudsql/{Endpoint}" : Endpoint,
UserID = User,
Password = Password,
Database = Schema,
Pooling = true
};
switch (IsCloud)
{
case true: builder.ConnectionProtocol = MySqlConnectionProtocol.UnixSocket; break;
case false: builder.Port = Convert.ToUInt32(Port); break;
}
_connectionString = builder.ConnectionString;
return _connectionString;
我还将云 SQL 连接添加到 Cloud Run 修订配置中。但每次我运行它并且容器必须访问数据库时,我都会收到未知套接字错误
并且没有任何进展。我的代码与 Google 推荐的代码基本相同,但我显然在设置套接字时做错了一些事情,因为当我使用公共 IP 时,一切都可以正常工作。
不幸的是,我不知道我可能做错了什么,并希望得到任何建议。 IsCloud 开关在那里,因此代码也可以在本地主机上运行,这需要加密和端口。
I'm running a .NET 6 service on Cloud Run and trying to connect using the built in socket. My instance name is project-id:region:instance-name
and the code for building my connection is as follows...
var builder = new MySqlConnectionStringBuilder
{
SslMode = IsCloud ? MySqlSslMode.None : MySqlSslMode.Required,
Server = IsCloud ? quot;/cloudsql/{Endpoint}" : Endpoint,
UserID = User,
Password = Password,
Database = Schema,
Pooling = true
};
switch (IsCloud)
{
case true: builder.ConnectionProtocol = MySqlConnectionProtocol.UnixSocket; break;
case false: builder.Port = Convert.ToUInt32(Port); break;
}
_connectionString = builder.ConnectionString;
return _connectionString;
I also added the cloud SQL connection to the Cloud Run revision configuration. But every time I run it and the container has to hit the database, I get an unknown socket error
and nothing to go on. My code is basically the same as the code recommended by Google, but I'm obviously doing something wrong setting up my socket because when I use a public IP, everything works without a problem.
Unfortunately, I have no idea what I could be doing wrong and would appreciate any advice. The IsCloud
switch is there so the code can also be ran on localhost, which requires encryption and a port.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在相同的设置下遇到了这个问题,结果实际上是 mySQL 权限问题。当我将 EntityFrameWorkCore MySQL 包降级到早期版本时,实际上我从 mySQL 中收到了未经授权的错误,但在新的 EntityFrameWorkCore 连接器中,它只是给出了未知套接字错误。
最新的 .net 6
降级软件包
我修复了权限并且工作正常。在本地,它工作得很好,因为我正在与不同的用户进行测试。
I had this issue with the same setup, and it actually turned out to be a mySQL permission issue. When I downgraded the EntityFrameWorkCore MySQL packages to earlier versions, I actually got an unauthorized error from mySQL, but in the new EntityFrameWorkCore connectors it just gave an unknown socket error.
Lastest on .net 6
Downgraded packages
I fixed the permisson and it works fine. Locally it worked fine as I was testing with a different user.