You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python连接AWS RDS MySQL数据库超时问题求助

使用Python连接AWS RDS MySQL数据库超时问题求助

我刚在AWS RDS上搭建了一个新的MySQL数据库,但用Python连接的时候一直遇到问题。我已经跟着AWS的指南完成了一系列操作——比如把安全组调整为允许任意IP地址访问(只是暂时这么设置,先解决当前连接问题)、关联了EC2实例等等,但还是搞不清楚到底哪里出错了。

以下是我用的Python代码(数据库信息已打码):

import mysql.connector

db_config = {
    'user': 'db_user',
    'password': 'user_password',
    'host': 'host',
    'database': 'db_name',
    'port': '3306',
    'connection_timeout': 10
}

try:
    connection = mysql.connector.connect(**db_config)
    if connection.is_connected():
        print("Connected to the MySQL database")
except mysql.connector.Error as err:
    print(f"Error: {err}")
finally:
    if 'connection' in locals() and connection.is_connected():
        connection.close()
        print("Connection closed")

运行这段代码后,Python返回的具体错误信息(数据库地址已打码),我觉得应该是超时错误:

Error: 2003 (HY000): Can't connect to MySQL server on 'db_host' (10060)

有没有大佬能给点思路或者解决办法呀?哪怕是比AWS官方指南更细致的排查步骤也行!

备注:内容来源于stack exchange,提问作者UserN600

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 11:24:33