Bug #109366 MySQL Python Connector doesn't work with ssh in the same process

Submitted: 13 Dec 2022 15:06 Modified: 4 Jul 2025 20:41
Reporter: Ahmed Nematallah Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:8.0.30+ OS:Any
Assigned to: CPU Architecture:Any

[13 Dec 2022 15:06] Ahmed Nematallah
Description:
Using MySQL python connector (8.0.30, 8.0.31) with ssh in the same process throws a "mysql.connector.errors.ProgrammingError: Character set 'utf8' unsupported" error. The server version is (5.6.33-log).

Version (8.0.29) works well regardless of anything.

Version (8.0.31) works well when setting up an external SSH connection to the same server (ssh -L 3306:example.com:3306 a@test.com, or creating the tunnel in one terminal window and connecting from another), but when using an SSH tunnel it fails.

Tested both using the sshtunnel library and paramiko/socketserver/threading/multiprocessing.

Note, to reproduce this error, you need to use "mysql.connector.MySQLConnection" as "mysql.connector.connect" simply hangs.

Sample code to set up a tunnel in paramiko/socketserver is here
https://github.com/paramiko/paramiko/blob/main/demos/forward.py

Sample code to connect to a MySQL server using sshtunnel is below:

How to repeat:
import mysql.connector
import sshtunnel

ssh_server='test.com'
ssh_port=22
ssh_uname='usr'
ssh_pwd='pwd'

db_server='example.com'
db_port=3306
db_uname='user'
db_pwd='pass'

tunnel = sshtunnel.SSHTunnelForwarder((ssh_server, ssh_port), ssh_username=ssh_uname, ssh_password=ssh_pwd, remote_bind_address=(db_server, db_port), local_bind_address=("127.0.0.1", 0))

# This line causes an exception
conn = mysql.connector.MySQLConnection(host=tunnel.local_bind_address[0], user=db_uname, password=db_pwd, port=tunnel.local_bind_address[1])

c = conn.cursor()

query = '''SELECT VERSION();'''
c.execute(query)
data = c.fetchall()
print(data)

conn.close()
tunnel.close()
[5 Jan 2023 12:03] MySQL Verification Team
Hello Ahmed,

Thank you for the bug report.
Verified as described.

Regards,
Ashwini Patil
[16 Apr 2025 15:09] Souma Kanti Ghosh
Posted by developer:
 
Hello Ahmed,

Thank you for reporting the bug.

Thanks and Regards,
Souma
[4 Jul 2025 20:41] Daniel So
Posted by developer:
 
Added the following entry to the Connector/Python 9.4.0 changelog (shared with Bug#34844347): 

"When using the Connector/Python C Extension, connections to a server using an sshtunnel failed, with the connection hanging or a segmentation fault."

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.