Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- import sshtunnel
- with sshtunnel.SSHTunnelForwarder(
- ("remote_ip", 22),
- ssh_username="centos",
- ssh_pkey="~/.ssh/id_rsa",
- remote_bind_address=("mysql_host", 3306),
- ) as tunnel:
- connection = MySQLdb.connect(
- user="mysql_user",
- password="mysql_password",
- host="127.0.0.1",
- database="database_name",
- port=tunnel.local_bind_port)
Add Comment
Please, Sign In to add comment