Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to change to another MySQL database (from backand) from my current one. So, I suppose it is about the way I set the database settings.

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

it returns this error

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

When I use another settings,

engine = create_engine('mysql+mysqldb://user:[email protected]:3306')
df_2.to_sql(name='KLSE', con=engine, if_exists='replace')

It returns this error

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

Below is the MySQL database information provided

  Database Type:
    mysql
    Endpoint:
    bk-prod-us1.cd2junihlkms.us-east-1.rds.amazonaws.com:3306
    Database name:
    backands146367311ktcttuv7
like image 834
vindex Avatar asked May 26 '16 14:05

vindex


1 Answers

try to specify the database name in your DB URL after the port number, like this:

engine = create_engine('mysql+mysqldb://user:[email protected]:3306/backands146367311ktcttuv7'
like image 78
MaxU - stop WAR against UA Avatar answered Sep 27 '22 18:09

MaxU - stop WAR against UA