社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

无法连接到AWS Aurora DB服务器--mysql引擎

nikhil int • 3 年前 • 1351 次点击  

我已经创建了一个AWS Aurora DB serverless公共可用,我正在尝试使用python连接到数据库。但我无法连接,我怀疑VPC。

请建议如果我必须检查任何其他内容,我也有以下问题;

  • AWS Aurora serverless with min配置是否为免费轮胎数据库?
  • 创建数据库时,我的VPC已经是公共的,但我无法连接,所以我需要执行任何其他配置更改吗?

代码片段:

import mysql.connector as mysq
import sys, os, boto3 as aws, pandas as pd, pymysql
from sqlalchemy import create_engine, inspect

ENDPOINT = "random.cluster-random.ap-south-1.rds.amazonaws.com"
PORT = "3306"
USER = "random"
REGION = "ap-south-1"
DBNAME = "random"
PASSWORD = "random"

方法1:

client = aws.client('rds')
token = client.generate_db_auth_token(DBHostname=ENDPOINT, Port=PORT, DBUsername=USER, Region=REGION)
print(token)

try:
    conn =  mysq.connect(host=ENDPOINT, user=USER, passwd=token, port=PORT, database=DBNAME)

    cur = conn.cursor()
    cur.execute("""SELECT now()""")
    query_results = cur.fetchall()
    print(query_results)
except Exception as e:
    print("Database connection failed due to {}".format(e))

方法2:

CONNECTION_STRING = 'mssql+pymssql' + '://' + USER + ':' + PASSWORD + '@' + ENDPOINT + ':' + str(PORT) + '/' + DBNAME
engine = create_engine(CONNECTION_STRING)
print(inspect(engine).get_table_names())

方法3:

conn = pymysql.connect(host=ENDPOINT, user=USER,port=int(PORT), passwd=PASSWORD, db=DBNAME)

谢谢 尼基尔

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131553
 
1351 次点击  
文章 [ 1 ]  |  最新文章 3 年前
Marcin
Reply   •   1 楼
Marcin    3 年前

无服务器极光 没有公共ip 类型 docs .

您不能为Aurora无服务器v1 DB群集提供公共IP地址。您只能从VPC内访问Aurora无服务器v1 DB群集。

Aurora v2也一样。

因此,您必须在家庭/工作网络和VPC之间设置VPN,或者通过一些ec2实例堡垒主机使用SSH隧道。