发现网上都是mysql,后面发现PG跟mysql差不多,记录下来,怕忘了
import psycopg2from DBUtils.PooledDB import PooledDBimport psycopg2.extraspool = PooledDB(psycopg2, 10,database="boatdb", user="postgres", password="xxxx", host="127.0.0.1", port="5432")print("connect success")conn = pool.connection()cur = conn.cursor()SQL = "select * from car_data"r = cur.execute(SQL)r = cur.fetchall()cur.close()conn.close()下面是MySQL的import MySQLdbfrom DBUtils.PooledDB import PooledDBpool = PooledDB(MySQLdb,5,host='localhost',user='root',passwd='pwd',db='myDB',port=3306) #5为连接池里的最少连接数 conn = pool.connection() #以后每次需要数据库连接就是用connection()函数获取连接就好了cur=conn.cursor()SQL="select * from table1"r=cur.execute(SQL)r=cur.fetchall()cur.close()conn.close()复制代码