如何使用 sqlalchemy 或 SQLObject 建立需要 CA-CERT 的 mysql 连接
我想连接到需要 ca-cert 的 MySQL 数据库。我可以使用 MySQLdb 来完成此操作,如下所示:
MySQLdb.connect(host = self.host,
port = self.port,
unix_socket = self.unix_socket,
user = self.user,
passwd = self.passwd,
db = self.db,
ssl = { 'cert': self.sslcert,
'key': self.sslkey,
'ca': self.sslca }
How do I do the same think in SQLAlchemy or SQLObject?
谢谢, 彼得
I would like to connect to a MySQL database that requires ca-cert. I can do it with MySQLdb like below:
MySQLdb.connect(host = self.host,
port = self.port,
unix_socket = self.unix_socket,
user = self.user,
passwd = self.passwd,
db = self.db,
ssl = { 'cert': self.sslcert,
'key': self.sslkey,
'ca': self.sslca }
How do I do the same think in SQLAlchemy or SQLObject?
Thanks,
peter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要将 SSL 证书与 SQLAlchemy 和 MySQLdb 一起使用,请使用以下 python 代码:
To use SSL certs with SQLAlchemy and MySQLdb, use the following python code:
SQLAlchemy 中的 create_engine() 有一个
connect_args参数:
create_engine() in SQLAlchemy has a
connect_args
parameter:SQLObject(未经测试):
SQLObject (untested):
根据他们的文档,SQLAlchemy的
create_engine
函数采用以下格式的 db url:dialect[+driver]://user:password@host/dbname[?key=value..]
表示您可以通过ssl key、cert 和 ca 作为键值对。According to their docs, SQLAlchemy's
create_engine
function takes a db url with the following format:dialect[+driver]://user:password@host/dbname[?key=value..]
meaning you could pass the ssl key, cert, and ca as key value pairs.