import mysql.connector
import sshtunnel
import pandas as pd
sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0
with sshtunnel.SSHTunnelForwarder(
('ssh.pythonanywhere.com',22),
ssh_username='myuser', ssh_password='mypass',
remote_bind_address=('my_user.mysql.pythonanywhere-services.com',3306)
) as tunnel:
connection = mysql.connector.connect(user='myuser', password='mypass',host='127.0.0.1', port=tunnel.local_bind_port,database='myuser$mydb')
sql = 'SELECT * from history'
df = pd.read_sql(sql, con=connection)
print(df.head())
connection.close()