[Python] Enable Python to Connect to MySQL via SSH Tunnelling

Discussão em 'Python' iniciado por Stack, Julho 31, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using MySqldb with Python 2.7 to allow Python to make connections to another MySQL server

    import MySQLdb
    db = MySQLdb.connect(host="sql.domain.com",
    user="dev",
    passwd="*******",
    db="appdb")


    Instead of connecting normally like this, how can the connection be made through a SSH tunnel using SSH key pairs?

    The SSH tunnel should ideally be opened by Python. The SSH tunnel host and the MySQL server are the same machine.

    Continue reading...

Compartilhe esta Página