sshtunnel

import mysql.connector from mysql.connector import Error from sshtunnel import SSHTunnelForwarder server = SSHTunnelForwarder( ('xy', 22), ssh_username="web", ssh_password=None, remote_bind_address=('127.0.0.1', 3306), local_bind_address=('0.0.0.0', 3310) ) def connect(): """ Connect to MySQL database """ try: conn = mysql.connector.connect(host='127.0.0.1', database='main_db', user='xx', password='xxx', port=3310) if conn.is_connected(): print('Connected to MySQL database') cursor = conn.cursor() cursor.execute("SELECT CODE,DATA FROM JOBS WHERE LANGUAGE = 'HU' ;") #print(cursor.fetchone()) #result=cursor.fetchone() result=cursor.fetchall() for row in result: print (row[0],' ',row[1]) except Error as e: print(e) finally: cursor.close() conn.close() server.start() connect() server.stop()

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.