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
SQLAlchemy supports MySQL starting with version 5.0. 2 through modern releases, as well as all modern versions of MariaDB.
SQLAlchemy provides a nice “Pythonic” way of interacting with databases. So rather than dealing with the differences between specific dialects of traditional SQL such as MySQL or PostgreSQL or Oracle, you can leverage the Pythonic framework of SQLAlchemy to streamline your workflow and more efficiently query your data.
The create_engine() method of sqlalchemy library takes in the connection URL and returns a sqlalchemy engine that references both a Dialect and a Pool, which together interpret the DBAPI's module functions as well as the behavior of the database.
To use SSL certs with SQLAlchemy and MySQLdb, use the following python code:
db_connect_string='mysql://<user>:<pswd>@<db server>:3306/<database>'
ssl_args = {'ssl': {'cert':'/path/to/client-cert',
'key':'/path/to/client-key',
'ca':'/path/to/ca-cert'}}
create_engine(db_connect_string, connect_args=ssl_args)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With