我尝试过在其他问题上找到的解决方案,但没有一个对我有用。我试图通过设置 ssh 隧道从远程服务器上运行的 mysql 数据库中提取数据。我的代码如下:
server = sshtunnel.SSHTunnelForwarder(
('10.6.41.10', 22),
ssh_username= 'serveruser',
ssh_password= 'serverpw',
remote_bind_address=('127.0.0.1', 3306))
server.start()
print(server.local_bind_port)
cnx = mysql.connector.connect(user='root', password='mysqlpw',
host='127.0.0.1',
database='mydb',
charset='utf8',
use_unicode='FALSE',
port = 3306)
但是,当我运行此代码时,我收到:
1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
我也尝试过添加
local_bind_address = ('0.0.0.0', 3306)
到 ssh 隧道设置并收到
Problem setting SSH Forwarder up: Couldn't open tunnel 0.0.0.0:3306 <> 127.0.0.1:3306 might be in use or destination not reachable
我不完全理解remote_bind_address和local_bind_address,所以我的猜测是那里肯定做错了什么。我知道我的用户名/密码/服务器信息是正确的,我可以通过终端 ssh 进入我的服务器,然后使用
mysql -h 127.0.0.1 -u root -p
成功登录我的mysql服务器。那么我需要修复什么才能让它在 python 中运行呢?谢谢。