Python sshtunnel模块无法连接mysql db

时间:2018-10-05 12:41:37

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

我正在尝试使用python模块“ sshtunnel”通过ssh隧道连接mysql db,但它抛出类似以下错误:

  

mysql.connector.errors.ProgrammingError:1045(28000):用户'sql_user_name'@'172.45.678.910'的访问被拒绝(使用密码:是)

这是我的代码

import mysql.connector
import sshtunnel

with sshtunnel.SSHTunnelForwarder(
    (ssh_host,ssh_port),
    ssh_username = ssh_username,
    ssh_pkey = ssh_pkey_path,
    remote_bind_address=(sql_host, sql_port),
    local_bind_address=("127.0.0.1",8080)) as server:
        mydb = mysql.connector.connect(host=sql_host,user=sql_user_name,password=sql_pwd,db=db_name)
        myCursor = mydb.cursor()

我的用户名和密码正确,我可以使用相同的凭据和相同的ssh主机通过sequal_pro成功连接,那么为什么在这里抛出错误? 并且在显示的ssh_host('172.45.678.910')错误消息中也有所不同,我从不在代码中使用此ssh_host,在变量“ ssh_host”中,ip也不同, 我尝试了互联网上所有可用的解决方案,但无法解决此问题

0 个答案:

没有答案
相关问题