背景
安装
pip install dbutils
使用
import pymysql
from dbutils.pooled_db import PooledDB
pool = PooledDB(pymysql,50,host='localhost',user='root',passwd='pwd',db='myDB',port=3306 charset="utf8") #5为连接池里的最少连接数
conn = pool.connection() #以后每次需要数据库连接就是用connection()函数获取连接就好了
cur=conn.cursor()
SQL="select * from table1"
r=cur.execute(SQL)
r=cur.fetchall()
cur.close()
conn.close()