Forums

Code snippet for SqlAlchemy and SSHTunnel please

hi team, I am using sqlachemy and pandas as below, to_sql and read_sql functions is all that I need.

from sqlalchemy import create_engine, text
import pandas as pd

engine = create_engine('mysql+mysqldb://tirtha9live:S1ndbad321@tirtha9live.mysql.pythonanywhere-services.com/tirtha9live$nsepricedb', pool_recycle=280)

con = engine.connect()

then I use pandas inbult function to write/read database tables

df = pd.read_sql(tablename, con=engine, index_col=indexcolumn, params=None)

Can I please get the code snippet to work this over SSHTunnel like in this kb for mysql.connector https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere/

It's the same. Just do the stuff that connects to and uses the database in the place where the mysql connector is used.