[英]Python MySQLDB SSL Connection
I set my database to require ssl. 我将我的数据库设置为要求ssl。 I've confirmed I can connect to the db via command line by passing the public key [and have confirmed I can't connect if I do not pass public key] 我已经确认我可以通过命令行通过传递公钥来连接到数据库[并且已确认如果我不传递公钥则无法连接]
I get the same error in my django app as when I do not pass a key. 我在django应用程序中遇到的错误与我没有传递密钥时的错误相同。 It seems I've not setup my settings.py correctly to pass the path to the public key. 似乎我没有正确设置我的settings.py以将路径传递给公钥。
What's wrong with my settings? 我的设置有什么问题? I'm using python-mysqldb. 我正在使用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',
}
}
Found the answer. 找到了答案。 OPTIONS should look like this: 选项应如下所示:
'OPTIONS': {'ssl': {'ca':'/path/to/cert.pem',},},
Make sure you keep the commas, parsing seemed to fail otherwise? 确保你保留逗号,否则解析似乎失败了?
The mysql client must be provided with three keys: 必须为mysql客户端提供三个密钥:
CA cert client cert client key CA证书客户端证书客户端密钥
See the Mysql documentation for the instructions for creating these keys and setting up the server: http://dev.mysql.com/doc/refman/5.5/en/creating-ssl-certs.html 有关创建这些密钥和设置服务器的说明,请参阅Mysql文档: http : //dev.mysql.com/doc/refman/5.5/en/creating-ssl-certs.html
NOTE: There is an open issue that seems to be related to using openssl v1.0.1 to create the certificates for mysql 5.5.x (http://bugs.mysql.com/bug.php?id=64870) 注意:有一个开放的问题似乎与使用openssl v1.0.1为mysql 5.5.x创建证书有关(http://bugs.mysql.com/bug.php?id=64870)
This is an example entry for the Django settings file: 这是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>'
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.