由于未知套接字错误,无法连接到 Google Cloud Run 上的 MySQL

发布于 2025-01-10 11:26:00 字数 1006 浏览 1 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追风人 2025-01-17 11:26:01

我在相同的设置下遇到了这个问题,结果实际上是 mySQL 权限问题。当我将 EntityFrameWorkCore MySQL 包降级到早期版本时,实际上我从 mySQL 中收到了未经授权的错误,但在新的 EntityFrameWorkCore 连接器中,它只是给出了未知套接字错误。

最新的 .net 6

System.Net.Sockets.SocketException (0xFFFDFFFE): Unknown socket error

降级软件包

MySqlConnector.MySqlException (0x80004005): Access denied for user 'xxxxxx' to database 'xxxx'

我修复了权限并且工作正常。在本地,它工作得很好,因为我正在与不同的用户进行测试。

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

System.Net.Sockets.SocketException (0xFFFDFFFE): Unknown socket error

Downgraded packages

MySqlConnector.MySqlException (0x80004005): Access denied for user 'xxxxxx' to database 'xxxx'

I fixed the permisson and it works fine. Locally it worked fine as I was testing with a different user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文