发现网上都是mysql,后面发现PG跟mysql差不多,记录下来,怕忘了
import psycopg2
from DBUtils.PooledDB import PooledDB
import psycopg2.extras
pool = 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 MySQLdb
from DBUtils.PooledDB import PooledDB
pool = PooledDB(MySQLdb,5,host='localhost',user='root',passwd='pwd',db='myDB',port=3306)
conn = pool.connection()
cur=conn.cursor()
SQL="select * from table1"
r=cur.execute(SQL)
r=cur.fetchall()
cur.close()
conn.close()
复制代码