使用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
相关产品推荐
相关产品推荐

