使用Python和SQLAlchemy从Google Cloud Function连接到Cloud SQL [英] Connecting to Cloud SQL from Google Cloud Function using Python and SQLAlchemy

查看:85
本文介绍了使用Python和SQLAlchemy从Google Cloud Function连接到Cloud SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了与从GCF连接到Cloud SQL中托管的MysQL有关的所有文档仍然无法连接.另外,尝试了

I read all documentation related to connecting to MysQL hosted in Cloud SQL from GCF and still can't connect. Also, tried all hints in documentation of SQLAlchemy related to this. I am using the following connection

con = 'mysql+pymysql://USER:PASSWORD@/MY_DB?unix_socket=/cloudsql/Proj_ID:Zone:MySQL_Instance_ID'
mysqlEngine = sqlalchemy.create_engine(con)

我得到的错误是:

(pymysql.err.OperationalError)(2003,无法连接到'localhost'上的MySQL服务器([Errno 111]连接被拒绝)")(此错误的背景位于:

推荐答案

在获得Google支持的长期支持后,我们发现原因是:我们应该在没有任何防火墙规则的情况下启用对Cloud SQL的公共访问.它没有证件,可能使您发疯,但是支持团队的银弹说:它是beta版!

After a long thread with Google Support, we found the reason to be: simply we should enable public access to Cloud SQL without any firewall rule. It is undocumented and can drive you crazy, but the silver bullet for the support team is to say: it is in beta!

这篇关于使用Python和SQLAlchemy从Google Cloud Function连接到Cloud SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆