SSL Connection Error while using MySQL Connector with Python
This worked for me (Ubuntu 16.04 LTS). From terminal:
- re-create certificates (datadir is of your choice):
mysql_ssl_rsa_setup --datadir=/data/dir/
- Add the following to
/etc/mysql/mysql.conf.d/mysqld.cnf
:
ssl-ca=/data/dir/cacert.pem ssl-cert=/data/dir/server-cert.pem ssl-key=/data/dir/server-key.pem
- Restart mysql server:
sudo service mysql restart
This only seems to happen when the mysql-connector-python
library uses the C extensions instead of the pure python implementation.
Since version 8.0.11, the default changed and it now uses the C extensions if they're present.
https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
One solution is to force the connector tu use the python implementation via that flag, just adding it to the connection url in your configuration:
url = 'mysql+mysqlconnector://user:password@mysql_server/database?use_pure=True'
I ran into the same issue on my mac, I was running mysql-connector-python version 8.0.16, I fixed the issue by downgrading to version 8.0.5
I had the same issue and resolved it by adding use_pure=True
argument based a suggestion here:
import mysql.connector as sql
db_connection = sql.connect(host='****', database='****', user='****', password='****', use_pure=True)
Relevant packages on my mac: mysql-connector-python 8.0.16
and openssl 1.1.1b
installed (both anaconda).