gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:12:30 25 4
gpt4 key购买 nike

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

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

它返回这个错误

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')

它返回这个错误

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'

关于mysql - Python : df. to_sql with OperationalError 1046, 'No database selected and OperationalError 2005, "Unknown MySQL server hos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37464191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com