Python: df.to_sql with OperationalError 1046, 'No database selected and OperationalError 2005, "Unknown MySQL server hos

Python: df.to_sql with OperationalError 1046, 'No database selected and OperationalError 2005, "Unknown MySQL server hos

我想从我当前的数据库切换到另一个 MySQL 数据库(从后台)。所以,我想这与我设置数据库设置的方式有关。

engine = create_engine('mysql+mysqldb://user:pw@backands146367311ktcttuv7')
df_2.to_sql(name='KLSE', con=engine, if_exists='replace')

它returns这个错误

OperationalError: (_mysql_exceptions.OperationalError) (2005, "Unknown MySQL server host 'backands146367311ktcttuv7' (0)")

当我使用其他设置时,

engine = create_engine('mysql+mysqldb://user:pw@bk-prod-us1.cd2junihlkms.us-east-1.rds.amazonaws.com:3306')
df_2.to_sql(name='KLSE', con=engine, if_exists='replace')

是returns这个错误

OperationalError: (_mysql_exceptions.OperationalError) (1046, 'No database selected') [SQL: 'DESCRIBE `KLSE`']

下面是提供的MySQL数据库信息

  Database Type:
    mysql
    Endpoint:
    bk-prod-us1.cd2junihlkms.us-east-1.rds.amazonaws.com:3306
    Database name:
    backands146367311ktcttuv7

尝试在端口号后指定数据库中的数据库名称 URL,如下所示:

engine = create_engine('mysql+mysqldb://user:pw@bk-prod-us1.cd2junihlkms.us-east-1.rds.amazonaws.com:3306/backands146367311ktcttuv7'