Working Ninja
2018-06-29T20:53:23
"Bad handshake" with mysql-connector-python Package

After updating mysql-connector-python to 8.0.11 (released April 19, 2018), I received an "OperationalError: 1043 (08S01): Bad handshake" error when querying a MySQL database. I found that I needed to set 'use_pure: True' in the connection string.

From the MySQL folks:

The C extension was added in version 2.1.1 and is enabled by default as of 8.0.11. The use_pure option determines whether the Python or C version of this connector is enabled and used.1

For example2:

import mysql.connector

config = {
  'user': 'scott',
  'password': 'password',
  'host': '127.0.0.1',
  'database': 'employees',
  'use_pure': True,
}

cnx = mysql.connector.connect(**config)

Since I don't have the C extension installed on my server, I reverted back to the Python implementation. Though it is good to know that the C extension can improve performance for large queries--something to tuck away for future use.

Sources:
1https://dev.mysql.com/doc/connector-python/en/connector-python-cext.html
2https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html