SSL Connection Error while using MySQL Connector with Python

后端 未结 5 2049
余生分开走
余生分开走 2021-01-02 07:38

I\'m using Python 3.6 (but I get the same error with Python 2.7) and mysql-connector-python in an Anaconda\'s environment to code a simple script to access my database hoste

相关标签:
5条回答
  • 2021-01-02 08:08

    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'
    
    0 讨论(0)
  • 2021-01-02 08:14

    I had the exact same problem, but since I was unable to use mlcr's solution (it was an AWS RDS database) my solution was different. I had to change mysql-connector-python versions from 8.x.x to 2.2.3. That resolved my issue entirely. Hope this helps someone.

    0 讨论(0)
  • 2021-01-02 08:29

    This worked for me (Ubuntu 16.04 LTS). From terminal:

    1. re-create certificates (datadir is of your choice):

    mysql_ssl_rsa_setup --datadir=/data/dir/

    1. 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
    
    1. Restart mysql server: sudo service mysql restart
    0 讨论(0)
  • 2021-01-02 08:31

    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).

    0 讨论(0)
  • 2021-01-02 08:31

    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

    0 讨论(0)
提交回复
热议问题