如何使用 sqlalchemy 或 SQLObject 建立需要 CA-CERT 的 mysql 连接

2021-12-30 00:00:00 python sqlalchemy mysql sqlobject

我想连接到需要 ca-cert 的 MySQL 数据库.我可以像下面这样用 MySQLdb 做到这一点:

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 } 

我如何在 SQLAlchemy 或 SQLObject 中实现相同的想法?

How do I do the same think in SQLAlchemy or SQLObject?

谢谢,彼得

推荐答案

SQLAlchemy 中的 create_engine() 有一个 connect_args 参数:

connect_args - 将直接传递的选项字典到 DBAPI 的 connect() 方法作为附加关键字参数.

connect_args – a dictionary of options which will be passed directly to the DBAPI’s connect() method as additional keyword arguments.

相关文章