-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathssh.py
More file actions
21 lines (18 loc) · 670 Bytes
/
Copy pathssh.py
File metadata and controls
21 lines (18 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from sshtunnel import SSHTunnelForwarder
import pymysql
import pandas as pd
with SSHTunnelForwarder(
('ec2-***-***-***-***.ap-southeast-1.compute.amazonaws.com'),
ssh_username="ec2-user",
ssh_pkey="D:\keys\bastion-kp.pem",
remote_bind_address=('db-instance.name.ap-southeast-1.rds.amazonaws.com', 3306)
) as tunnel:
print("****SSH Tunnel Established****")
db = pymysql.connect(
host='127.0.0.1', user="admin | root",
password="************", port=tunnel.local_bind_port
)
sql = 'SELECT * from TableName"'
dataFrame = pd.read_sql(sql, db, index_col='id')
print(dataFrame.head())
print("Data Fetched .....")