Python数据库连接池DBUtils.PooledDB,,python不用连接池的
Python数据库连接池DBUtils.PooledDB,,python不用连接池的
python不用连接池的MySQL连接方法
import MySQLdbconn= MySQLdb.connect(host='localhost',user='root',passwd='pwd',db='myDB',port=3306) cur=conn.cursor()SQL="select * from table1"r=cur.execute(SQL)r=cur.fetchall()cur.close()conn.close()
用连接池后的连接方法
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()
DBUtils下载地址:https://pypi.python.org/pypi/DBUtils/
相关内容
- python下载大文件代码,python文件代码,如果下载小文件,
- python利用PIL库读取图片的EXIF信息,,NonePIL库下载地址
- paramiko+threading批量检查系统状态,paramikothreading,#!/usr
- python模拟登录v2ex,python模拟v2ex,# coding=utf
- Python抓妹子图+多进程,python抓妹子图,# -*- coding
- Python抓妹子图+多进程,python抓妹子图,# -*- coding
- python线程池进一步认识,python线程池认识,线程池的概念
- python代码实例大小写转换,首字母大写,去除特殊字符,
- python操作mysql数据库代码,pythonmysql数据库,python操作m
- pygame simulate,pygame,import pygam
评论关闭