- 1 year ago
"SSL connection error: protocol version mismatch QMYSQL: Unable to connect"
This error usually occurs when there is a mismatch between the SSL protocol versions of the MySQL client and server. To fix the issue, you can try the following steps:
Check the SSL version used by your MySQL server: You can check the SSL version used by your MySQL server by running the following command in the MySQL console:
sqlSHOW VARIABLES LIKE '%ssl_version%';
This will show the SSL version used by the MySQL server.
Check the SSL version used by your MySQL client: You can check the SSL version used by your MySQL client by running the following command in your Python code:
arduinoimport MySQLdb
conn = MySQLdb.connect(host='yourhost', user='youruser', passwd='yourpassword', db='yourdb', ssl={'ssl': {'ssl_version': 'TLSv1.2'}})
cursor = conn.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print("Database version : %s " % data)
This will show the SSL version used by your MySQL client.
If there is a mismatch between the SSL versions used by the MySQL client and server, you can try changing the SSL version used by the client to match that used by the server. To do this, you can add the following line of code to your Python code:
sqlconn = MySQLdb.connect(host='yourhost', user='youruser', passwd='yourpassword', db='yourdb', ssl={'ssl': {'ssl_version': 'TLSv1.2'}})
In this line, change the
ssl_version
parameter to match the SSL version used by your MySQL server.If changing the SSL version does not work, you can try disabling SSL verification altogether by adding the following line of code to your Python code:
sqlconn = MySQLdb.connect(host='yourhost', user='youruser', passwd='yourpassword', db='yourdb', ssl={'ssl': {'ssl_version': 'TLSv1.2'}, 'check_hostname': False})
This will disable SSL verification and may allow the connection to succeed. However, this is not recommended for production use as it may leave your connection vulnerable to man-in-the-middle attacks.