Forums

MySQL remote connection

Dear All , I need to manage DB remotely , so i follow tutorial :

sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0
with sshtunnel.SSHTunnelForwarder(
    ('ssh.pythonanywhere.com'),
    ssh_username='user', ssh_password='sshpass',
    remote_bind_address=(''user.mysql.pythonanywhere-services.com'', 3306)
            ) as tunnel:

c = DAL('mysql://user:dbpass@127.0.0.1:'+str(tunnel.local_bind_port)+'/dbname',pool_size=0 )

but i can't read anything from db , c.tables return empty list. when i try with mysql.connector :

c = mysql.connector.connect(
                            user='user', password='dbpass',
                            host='127.0.0.1', port=tunnel.local_bind_port,
                            database='dbname',)
cur=c.cursor() , return  MySQL Connection not available

What i missing ?

[edited by admin: formatting]

everything is fine when establish ssh tunnel manually ... can't get where i'm wrong ...

which is the tutorial that you are following? Can you reformat the code that you have shown above? We cannot quite read it

this tutorial : https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere/ when i use DAL for connection can't read anything from db . when i use mysql.connector it return : MySQL Connection not available when establish manually ssh tunnel is working fine .

If the indentation in your original post is correct, then you are trying to use the connection when it is not available. You need to include the code that accesses the database inside the with statement that create the tunnel.