Python连接MySQL数据库的方法之一: from DBUtils.PersistentDB import PersistentDB import pymysql Pool = PersistentDB( creator=pymysql, maxusage=None, setsession=[], ping=0, closeable=False, threadlocal=None, host='localhost', port=
Python连接MySQL数据库的方法之一:
from DBUtils.PersistentDB import PersistentDBimport pymysql
Pool = PersistentDB(
creator=pymysql,
maxusage=None,
setsession=[],
ping=0,
closeable=False,
threadlocal=None,
host='localhost',
port=3307,
user='root',
password='111111',
database='testdb',
charset='utf8')
conn = Pool.connection()
cursor = conn.cursor()
cursor.execute('select * from book')
result = cursor.fetchall()
print(result)
cursor.close()
conn.close()
creator = pymysql, #使用链接数据库的模块
maxusage = None, #一个链接最多被使用的次数,None表示无限制
setsession = [], #开始会话前执行的命令
ping = 0, #ping MySQL服务端,检查服务是否可用
closeable = False, #conn.close()实际上被忽略,供下次使用,直到线程关闭,自动关闭链接,而等于True时,conn.close()真的被关闭
threadlocal = None, # 本线程独享值的对象,用于保存链接对象