1

I am trying to use mysql.connector in Python 3.7 to connect to an Amazon RDS MySQL database I created following this tutorial. In python if I try

mysql.connector.connect(host="hostname.rds.amazonaws.com",
                        user="username", passwd="password", 
                        database="databasename")

I get the following error:

MySQLInterfaceError: SSL connection error: SSL_CTX_set_tmp_dh failed

What is the error referring to? If I connect with the same credentials from the command line using mysql or mysql workbench I have no problems.

Update:

It must have been an issue with the anaconda environment I was using. I've since used pip3 to install mysql-connector and it works correctly.

3
  • AWS RDS switched from yaSSL to openssl right around where I noticed the problem (mysql 5.6.39) which I think was auto-updated since it's a minor version bump; I suspect it's a problem with the switch that may have been smoothed over by a different version of openssl when you used pip. aws link Commented Mar 6, 2019 at 18:22
  • Right thanks, could be. I've since removed anaconda so can't check whether the problem persists there. Commented Mar 8, 2019 at 11:41
  • Heh, that’s why I added a comment instead of an answer. ;) My solution was just to switch databases since this hasn’t hit production yet. I did also notice that conda recently bumped OpenSSL and tons of packages on conda-forge had to be rebuilt as well so it certainly seems like something there broke. Commented Mar 9, 2019 at 12:59

1 Answer 1

0

It failed to set a Diffie-Hellman parameter in your SSL context, probably due to a missing .pem file. Please see the django docs and SSL connection error when connecting to RDS MySQL from Django, which suggests adding an option like

DATABASES['default']['OPTIONS'] = {
    'ssl': {'ca': '/app/project_name/rds/mysql-ssl-ca-cert.pem'}
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for clarifying the error code. I don't really understand why this is coming up though, because I'm not trying to connect with ssl.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.