mysql - 如何以编程方式连接到我的 RDS MySQL 实例?
问题描述
问题
我启动了一个 MySQL RDS 实例,并能够使用 MySQL Workbench 成功连接到它。但是,我仍然无法使用以下 URI 从本地工作站连接到它:
'mysql+pymysql://user:password@db_identifier.XXXXXXXXXX.us-east-1.rds.amazonaws.com:3306/db_name'
或没有端口的相同 URI:
'mysql+pymysql://user:password@db_identifier.XXXXXXXXXX.us-east-1.rds.amazonaws.com/db_name'
当我将其指定为我的数据库 URI 并执行db.create_all()
命令时收到的错误是:
sqlalchemy.exc.OperationalError:
(pymysql.err.OperationalError)
(2003, "Can't connect to MySQL server on 'db_identifier.XXXXXXXXXX.us-east-1.rds.amazonaws.com'
([WinError 10060] A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection failed because
connected host has failed to respond)")
问题
如何使用 pymysql 进行连接?为什么它会连接 MySQL Workbench 而不是通过这个 URI?
语境
我正在关注这里的教程。这使用 SQLAlchemy 在 Python 中执行 SQL 语句。
RDS 实例(及其关联的子网/VPC)具有以下内容:
- 在端口 3306 上打开的安全组
- 允许传入和传出流量的 NACL 规则
- 公共可访问性设置为“是”
解决方案
检查我对这篇文章的回答,这可能与您的 rds“连接性和安全性”部分中的“公共可访问性”选项有关,如此处所述;
推荐阅读
- angular - node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11) 中的错误:错误 TS2451:无法重新声明块范围变量“ngDevMode”
- youtube-api - Youtube liveBroadcast 插入限制?
- javascript - 在 React 中使用 Map 和 firebase
- sql-server - 在同一张表中返回当月工资和上月工资
- raspberry-pi - BLE 6LoWPAN边界路由器的多连接
- scala - 在 Scala DataFrame 中迭代
- ruby-on-rails - 如何在 ruby on rails 中配置 highcharts 的 highmaps?
- javascript - React-Native 评论组件
- r - 在附加代码片段中的函数中调用函数时找不到错误
- javascript - Node.js - 使用 for 循环进行迭代是否确保我的回调按顺序依次调用?