我正在尝试通过我的一个谷歌云功能上的ssh隧道连接到MySQL服务器。这在我的家庭环境中效果很好。我认为这是云功能的一些端口问题
编辑:为了澄清问题,MySQL服务器位于一个共享托管web服务器上。不是谷歌云SQL
每次运行此命令时,我都会超时并显示“未知错误”。这条隧道似乎很成功。但是,我无法让mysql连接正常工作
import base64
import sshtunnel
import mysql.connector
def testing(event, context):
"""
Testing function
"""
with sshtunnel.SSHTunnelForwarder(
("server address", port),
ssh_username="user",
ssh_password="password",
remote_bind_address=("127.0.0.1",3306),
) as server:
print(server.local_bind_port)
with mysql.connector.connect(
user="user",
password="password",
host="localhost",
database="database",
port=server.local_bind_port
) as connection:
print(connection)
要列出的步骤太多了,但我想知道“连接器”设置是否对SSH也有影响。也许您必须创建一个连接器,如图here(注意“私有IP”选项卡中的说明与本地计算机上的不同)。然后,配置云函数以使用该连接器。确保您也使用了正确的端口
请记住,此“未知”错误也可能是由于未启用云SQL管理API here。事实上,请确保你关注整个页面,因为这是一个广泛的问题
让我们知道是什么导致了这种错误
相关问题 更多 >
编程相关推荐