My code to connect to MySQL sever is as below:
engine = create_engine('mysql+mysqldb://bkcollection:pw@bkcollecton.mysql.pythonanywhere-services.com')
conn = engine.raw_connection()
df_new.to_sql(name='KLSE', con=conn, if_exists='replace')
conn.close()
however, I have this error
File "/home/bkcollecton/test_f.py", line 236, in <module>
conn = engine.raw_connection()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1699, in raw_connection
return self.pool.unique_connection()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 220, in unique_connection
return _ConnectionFairy(self).checkout()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 431, in __init__
rec = self._connection_record = pool._do_get()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 788, in _do_get
con = self._create_connection()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 225, in _create_connection
return _ConnectionRecord(self)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 318, in __init__
self.connection = self.__connect()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py", line 379, in __connect
connection = self.__pool._creator()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py", line 80, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 283, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
sqlalchemy.exc.OperationalError: (OperationalError) (1045, "Access denied for user 'bkcollection'@'ip-10-61-196-73.ec2.internal' (usi
ng password: YES)") None None