Python - SSH Tunnel Setup and MySQL DB Access

前端 未结 1 412
予麋鹿
予麋鹿 2020-12-07 03:39

I am trying to connect to my server from my local(windows) and access the MySQL DB

With the below code setting up the SSH tunnel through putty, I am not able to acce

相关标签:
1条回答
  • 2020-12-07 04:19

    You can use sshtunnel wrapper for paramiko and save you headaches ;)

    from sshtunnel import SSHTunnelForwarder
    import MySQLdb
    
    with SSHTunnelForwarder(
             ('host', 22),
             ssh_password="password",
             ssh_username="username",
             remote_bind_address=('127.0.0.1', 3308)) as server:
    
        con = None
        con = mdb.connect(user='user',passwd='password',db='database',host='127.0.0.1',port=server.local_bind_port)
        cur = con.cursor()
    
    0 讨论(0)
提交回复
热议问题