Python MySQLDB SSL Connection

I set the ssl request for my database. I confirmed that I can connect to db via the command line by passing the public key [and confirmed that I can’t connect if I don’t pass the public key]

I get the same error in my django application as when I do not pass the key. It seems that I did not configure the settings.py settings correctly to pass the path to the public key.

What happened to my settings? I am using python-mysqldb.

DATABASES['default'] = {
    'ENGINE': 'django.db.backends.mysql',
    'HOST': 'my-host-goes-here',
    'USER': 'my-user-goes-here',
    'NAME': 'my-db-name-goes-here',
    'PASSWORD': 'my-db-pass-goes-here',
    'OPTIONS': {
        'SSL': '/path/to/cert.pem',
    }
}
+5
source share
2 answers

Found the answer. OPTIONS should look like this:

'OPTIONS': {'ssl': {'ca':'/path/to/cert.pem',},},

Make sure you keep the commas, the parsing doesn't seem to go the other way?

+8
source

mysql :

CA cert

. Mysql : http://dev.mysql.com/doc/refman/5.5/en/creating-ssl-certs.html

. , , , openssl v1.0.1 mysql 5.5.x(http://bugs.mysql.com/bug.php?id=64870)

Django:

DATABASES = {
'default': {
              'ENGINE': 'django.db.backends.mysql',  
              'NAME': '<DATABASE NAME>',                     
              'USER': '<USER NAME>',
              'PASSWORD': '<PASSWORD>',
              'HOST': '<HOST>', 
              'PORT': '3306'    
              'OPTIONS':  {
                        'ssl': {'ca': '<PATH TO CA CERT>',
                                'cert': '<PATH TO CLIENT CERT>',
                                'key': '<PATH TO CLIENT KEY>'
                                }
                          }
            }
}
+1

All Articles