使用python3.6通过ssh隧道连接到远程mysql数据库时出现问题?

dwthyt8l  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(224)

我正在尝试用python登录mysql服务器。我可以使用mysql workbench和相同的凭据轻松访问此服务,但使用以下代码时出现错误:

import MySQLdb as db
import sshtunnel
import pandas as pd
sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0

with sshtunnel.SSHTunnelForwarder(
    ('accesspoint.fake.com', 22),
    ssh_username='Tony',
    ssh_password='pwtony',
    remote_bind_address=('180.45.89.0', 3306)) as server:

    conn = db.connect(host='180.45.89.0',
                           port=server.local_bind_port,
                           user='Tony',
                           password='pwtony',
                           db='all_data')

错误消息:

--------------------------------------------------------
OperationalError       Traceback (most recent call last)
<ipython-input-16-ca168ce0a4a7> in <module>()
      9                            user='Tony',
     10                            password='pwtony',
---> 11                            db='all_data')

~/anaconda3/lib/python3.6/site-packages/MySQLdb/__init__.py in Connect(*args,**kwargs)
     84     """Factory function for connections.Connection."""
     85     from MySQLdb.connections import Connection
---> 86     return Connection(*args,**kwargs)
     87 
     88 connect = Connection = Connect

~/anaconda3/lib/python3.6/site-packages/MySQLdb/connections.py in __init__(self, *args,**kwargs)
    202         self.waiter = kwargs2.pop('waiter', None)
    203 
--> 204         super(Connection, self).__init__(*args,**kwargs2)
    205         self.cursorclass = cursorclass
    206         self.encoders = dict([ (k, v) for k, v in conv.items()

OperationalError: (2003, "Can't connect to MySQL server on '180.45.89.0' (110)")

如有任何帮助,将不胜感激:)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题