Python 多线程访问数据库正确使用dbutils PooledDB数据库连接池

1.安装DBUtils

pip install DBUtils

 2.db_helper.py的代码如下

import pymysql
from dbutils.pooled_db import PooledDB
from config import config


class DBHelper:

    def __init__(self):
        """
        :param mincached:连接池中空闲连接的初始数量
        :param maxcached:连接池中空闲连接的最大数量
        :param maxshared:共享连接的最大数量
        :param maxconnections:创建连接池的最大数量
        :param blocking:超过最大连接数量时候的表现,为True等待连接数量下降,为false直接报错处理
        :param maxusage:单个连接的最大重复使用次数
        :param setsession:optional list of SQL commands that may serve to prepare
            the session, e.g. ["set datestyle to ...", "set time zone ..."]
        :param reset:how connections should be reset when returned to the pool
            (False or None to rollback transcations started with begin(),
            True to always issue a rollback for safety's sake)
        :param host:数据库ip地址
        :param port:数据库端口
        :param db:数据库名
        :param user:用户名
        :param passwd:密码
        :param charset:字符编码
        """
        mincached = 0
        maxcached = 0
        maxshared = 0
        maxconnections = 0
        blocking = True
        maxusage = 0
        setsession = None
        reset = True
        host = config.mysql_config["host"]
        port = config.mysql_config["port"]
        db = config.mysql_config["database"]
        user = config.mysql_config["user"]
        passwd = config.mysql_config["password"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值