How to make mysql connection that requires CA-CERT with sqlalchemy or SQLObject

后端 未结 4 1417
刺人心
刺人心 2020-12-05 19:38

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,
                po         


        
相关标签:
4条回答
  • 2020-12-05 20:17

    SQLObject (untested):

    from sqlobject.mysql import MySQLConnection
    connection = MySQLConnection(
        db=self.db,
        user=self.user,
        password=self.password,
        host=self.host,
        ssl_key=self.sslkey,
        ssl_cert=self.sslcert,
        ssl_ca=self.sslca,
    )
    
    0 讨论(0)
  • 2020-12-05 20:19

    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.

    0 讨论(0)
  • 2020-12-05 20:23

    create_engine() in SQLAlchemy has a connect_args parameter:

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

    0 讨论(0)
  • 2020-12-05 20:37

    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)
    
    0 讨论(0)
提交回复
热议问题