MySQLConnection错误:用户'rnd-admin'@'localhost'的访问被拒绝(使用密码:是)

时间:2019-04-05 07:35:47

标签: python mysql ssh terminal mariadb

我正在尝试通过ssh隧道连接到远程服务器上的mysql数据库。
与服务器建立连接后,我的脚本因mysql错误而失败:

py.warnings - WARNING - /home/artur/Exposit/Projects/dataset-collector/venv/lib/python3.6/site-packages/paramiko/kex_ecdh_nist.py:39: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
  m.add_string(self.Q_C.public_numbers().encode_point())

py.warnings - WARNING - /home/artur/Exposit/Projects/dataset-collector/venv/lib/python3.6/site-packages/paramiko/kex_ecdh_nist.py:96: CryptographyDeprecationWarning: Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_point
  self.curve, Q_S_bytes

py.warnings - WARNING - /home/artur/Exposit/Projects/dataset-collector/venv/lib/python3.6/site-packages/paramiko/kex_ecdh_nist.py:111: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
  hm.add_string(self.Q_C.public_numbers().encode_point())

root - ERROR - 1045 (28000): Access denied for user 'rnd-admin'@'localhost' (using password: YES)
Access denied for user 'rnd-admin'@'localhost' (using password: YES).

注意: 当我使用mysql -u rnd-admin -p从具有相同信用的终端连接到数据库时,一切都很好,没有检测到错误,并且打开了mysql cli

        with SSHTunnelForwarder(
                ('myhost', 22),
                ssh_username="root",
                ssh_password="passwd",
                remote_bind_address=('127.0.0.1', 3306)) as tunnel:
            if tunnel.is_active:
                db_config = read_db_config()
                conn = MySQLConnection(**db_config)

                cursor = conn.cursor()
                cursor.execute(query)
                result = cursor.fetchall()

                conn.commit()
                cursor.close()
                conn.close()

config.ini

[mysql]
host=127.0.0.1
port=3306
database=db-name
user=rnd-admin
password=pass

1 个答案:

答案 0 :(得分:2)

通过从config.ini中删除 3306 mysql默认端口并手动将port=tunnel.local_bind_port馈入 MySQLConnection 构造函数来解决此问题。

conn = MySQLConnection(**db_config, port=tunnel.local_bind_port)