0

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='00.00.000.000',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__
    self.connect(**kwargs)
  File "/usr/local/lib/python2.6/dist-packages/mysql/connector/abstracts.py", line 719, in connect
    self._open_connection()
  File "/usr/local/lib/python2.6/dist-packages/mysql/connector/connection.py", line 210, in _open_connection
    self._ssl)
  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.

2
  • 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
    Commented Oct 19, 2016 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. Commented Oct 19, 2016 at 11:16

1 Answer 1

0
    >>>import mysql.connector
    >>>cnx = mysql.connector.connect(user='odbc_user', password='password',host='00.00.00.000',database='database',
        ssl_ca='/home/akelly/ca-cert.pem',
        ssl_cert='/home/akelly/client-cert.pem',
        ssl_key='/home/akelly/client-key.pem')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .