以前用MySQLdb和PooledDB写过一个后来找不到了,现在重新写一个。因为PooledDB似乎是不支持python3的,所以我这里使用的是mysql官方的连接器mysql.connector.pooling(我还是用python2.7写的,python3还没试过)。
mysql-connector-python的当前版本是2.1.3,可以在mysql的官网下载http://dev.mysql.com/downloads/connector/python/,或者我的资源里下载http://download.csdn.net/detail/paololiu/9640250。
#!/usr/local/bin/python
# -*- coding: utf8 -*-
'''
Created on 2016年9月21日
@author: PaoloLiu
'''
import mysql.connector.pooling
import logging
import time
class mysqlpool(object):
'''
classdocs
'''
def __init__(self, user, password, host, port, database, poolsize):
'''
Constructor
'''
dbconfig = {
"user": user,
"password": password,
"host": host,