MySQLConnectionPool 中的动态数据库和字典游标

dynamic database and dict cursor in MySQLConnectionPool

我一直在尝试在 python 中为 mysql 使用连接池。在搜索选项时,我遇到了 MySQLConnectionPool。它似乎工作正常,但我无法找到如何实现 MySQL.

的某些功能
  1. 如何动态 select 数据库。
  2. 如何使用dict_cursor。为了 正常 MySQL 没有池,我用 cursorclass=MySQLdb.cursors.DictCursor

如果有人知道如何实现这一点,请告诉我。提前致谢。

终于可以做到了

  1. 对于动态数据库,我在python中使用了Lock模块。因为我正在为服务器使用池,所以我会收到并发请求,这些请求不应完全改变连接池的数据库。
  2. 对于字典,在创建游标时我将参数 dictionary 的值设置为 True

    lock.acquire()
    try:
        self._pool.set_config(**conn_config)  //conn_config contains the modified database details
        conn = self._pool.get_connection()
        cursor = conn.cursor(dictionary=True)
    except PoolError:
       //do something
    lock.release()