使用SSHTunnelForwarder连接远程MYSQL数据库时出现连接错误

时间:2018-06-29 13:42:51

标签: mysql python-3.x mysql-python mysql-connector ssh-tunnel

我正在尝试使用sshtunnel连接远程MySQL数据库,但出现以下错误:

mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on 'WWW.XXX.YYY.ZZ' (10061)

我已尝试从stackoverflow /其他站点中的旧查询中找到可能的解决方案,但没有任何效果。

脚本:

import mysql.connector as myCon
import sshtunnel

server = sshtunnel.SSHTunnelForwarder(
    ('WWW.XXX.YYY.ZZ', 22),
    ssh_username='dbuser',
    ssh_password='dbuser',
    remote_bind_address=('WWW.XXX.YYY.ZZ', 3306)
    )

server.start()
connection = myCon.connect(host='WWW.XXX.YYY.ZZ', port=server.local_bind_port, user='demo', password='demo', database='ADC_test')

请帮助解决以下错误

错误:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\mysql\connector\connection_cext.py", line 176, in _open_connection
    self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Can't connect to MySQL server on 'WWW.XXX.YYY.ZZ' (10061)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Sunil_Work\psnl\python\pyCharm\PyMySQL\Connect to MYSQL.py", line 14, in <module>
    connection = myCon.connect(host='WWW.XXX.YYY.ZZ', port=server.local_bind_port, user='demo', password='demo', database='ADC_test')
  File "C:\Python36\lib\site-packages\mysql\connector\__init__.py", line 182, in connect
    return CMySQLConnection(*args, **kwargs)
  File "C:\Python36\lib\site-packages\mysql\connector\connection_cext.py", line 78, in __init__
    self.connect(**kwargs)
  File "C:\Python36\lib\site-packages\mysql\connector\abstracts.py", line 736, in connect
    self._open_connection()
  File "C:\Python36\lib\site-packages\mysql\connector\connection_cext.py", line 179, in _open_connection
    sqlstate=exc.sqlstate)
mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on 'WWW.XXX.YYY.ZZ' (10061)

0 个答案:

没有答案