Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make mysql connection that requires CA-CERT with 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

like image 739
cfpete Avatar asked Nov 04 '11 19:11

cfpete


People also ask

Can SQLAlchemy connect to MySQL?

SQLAlchemy supports MySQL starting with version 5.0. 2 through modern releases, as well as all modern versions of MariaDB.

Is SQLAlchemy same as MySQL?

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.

What is SQLAlchemy import Create_engine?

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.


1 Answers

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)
like image 62
Drew Avatar answered Oct 19 '22 08:10

Drew