mysql
python链接
# -*- coding:utf-8 -*-
# /usr/bin/python
'''
@Author: Yan Errol @Email:2681506@gmail.com
@Date: 2019-06-05 17:29
@File:ssh_connect_mysql.py
@Describe:通过跳板机,链接mysql
@Evn:
'''
import pymysql
from sshtunnel import SSHTunnelForwarder
# 程序主入口
if __name__ == "__main__":
# 跳板机SSH连接
with SSHTunnelForwarder(
('192.168.0.1', 22),
ssh_username="test",
ssh_pkey="test.pem",
remote_bind_address=('*************mysql.rds.aliyuncs.com', 3306)
) as tunnel:
# 数据库连接配置,host默认127.0.0.1不用修改
conn = pymysql.connect(
host='127.0.0.1',
port=tunnel.local_bind_port,
user='root',
password='root',
db='tes