简体   繁体   English

无法使用flask-sqlalchemy连接到aws RDS上的MySQL

[英]cant connect to MySQL on aws RDS with flask-sqlalchemy

I am trying to connect to an RDS instance with flask-sqlalchemy.我正在尝试使用 flask-sqlalchemy 连接到 RDS 实例。 But i cant get it to work.但我无法让它工作。 I am getting the error我收到错误

sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1049, "Unknown database 'dbname'")¨

My database URI looks like this我的数据库 URI 看起来像这样

SQLALCHEMY_DATABASE_URI = 'mysql://username:password@dbname.xxxxxxxxxxxx.eu-central-1.rds.amazonaws.com:3306/dbname'

I have tried using the pymysql plugin, but it didnt make any difference.我曾尝试使用 pymysql 插件,但没有任何区别。

I think my security groups are setup correctly.我认为我的安全组设置正确。 On the RDS instance it is this在 RDS 实例上是这个

一世

(I dont know if security groups contain any personnel info) (我不知道安全组是否包含任何人员信息)

Try creating the database first:先尝试创建数据库:

import pandas as pd
import sqlalchemy 

mysql_engine = sqlalchemy.create_engine("mysql://username:password@dbname.xxxxxxxxxxxx.eu-central-1.rds.amazonaws.com:3306")

pd.read_sql_query("create database dbname", con=mysql_engine)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM