# 环境 python3.7
# 第三方库安装:
pip install pymysql
pip install DBUtils
# 功能实现:建立mysql连接池,实现增删查改
import pymysql
import time
from DBUtils.PooledDB import PooledDB
class MysqldbHelper(object): # 继承object类所有方法
def __init__(self, config):
self.host = config['host']
self.username = config['user']
self.password = config['passwd']
self.db = config['db']
self.port = config['port']
while True:
try:
self.pool = PooledDB(pymysql, 5, host=self.host, user=self.username, passwd=self.password, db=self.db,
port=self.port,
cursorclass=pymysql.cursors.DictCursor)
except BaseException as e:
print(e)
self.pool = None