5

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:pw@bk-prod-us1.cd2junihlkms.us-east-1.rds.amazonaws.com: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
vindex
  • 331
  • 6
  • 17

1 Answers1

6

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

engine = create_engine('mysql+mysqldb://user:pw@bk-prod-us1.cd2junihlkms.us-east-1.rds.amazonaws.com:3306/backands146367311ktcttuv7'
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
  • although I have no error after I created the table, but when I search the database in backand.com, it said the tables was created with erros as there is no primary key. I use to create same database in db4free.net but with no issues. I do not understand why? – vindex May 27 '16 at 03:02
  • I am using sqlalchemy which is suppose to add primary key automatically – vindex May 27 '16 at 08:37