Using the below 3 PEM files I am able to connected successfully to a MySQL database on windows threw setting up a Data Source. (No problems here)

  • client-key.pem
  • client-cert.pem
  • ca-cert.pem

But I also want to be able to connect via Python code on an Ubuntu server 10.04. I have Python and the MySQL Python Connector setup. But as expected fails trying to connect with the credentials alone since authorisation threw these PEM certificates are required.

**>>>** import mysql.connector
**>>>** cnx = mysql.connector.connect(user='odbc_user', password='mypassword',host='',database='mydb')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/mysql/connector/__init__.py", line 179, in connect
    return MySQLConnection(*args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 95, in __init__
  File "/usr/local/lib/python2.6/dist-packages/mysql/connector/abstracts.py", line 719, in connect
  File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 210, in _open_connection
  File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 144, in _do_auth
    self._auth_switch_request(username, password)
  File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 177, in _auth_switch_request
    **raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'odbc_user'@'hide.ec2' (using password: YES)**

What I have tried based on searches but with no progress:

  • Copied the 3 .pem files to /usr/share/ca-certificates/ as .crt files.
  • Ran sudo update-ca-certificateswhich added these to the /etc/ssl/certs/ca-certificates.crt file.

I'm no Linux guru and just trying anything I come across so if someone has done this before I would much appreciate the help.

  • According to dev.mysql.com/doc/connector-python/en/… (section "Connecting through SSL") all you need to do is pass the appropriate arguments to mysql.connector.connect.
    – Wieland
    Oct 19 '16 at 9:31
  • My man. So obvious and easy once you know the answer. And I wasn't even looking at the Python itself as assumed I need to setup environment. Never considered passing the files with connection values. Oct 19 '16 at 11:16
    >>>import mysql.connector
    >>>cnx = mysql.connector.connect(user='odbc_user', password='password',host='',database='database',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.