我正在尝试在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)")
非常感谢任何帮助:)