直接上代码:
import mysql.connectorimport sys, osimport timebegintime = time.strptime("2013-10-21 0:0:0", "%Y-%m-%d %H:%M:%S")endtime = time.strptime("2013-11-21 0:0:0", "%Y-%m-%d %H:%M:%S")begin = time.mktime(begintime)end = time.mktime(endtime)user = 'root'pwd = '******'host = '192.168.27.78'db = 'bugtracker'select_sql = "SELECT realname from mantis_user_table where date_created between " + str(begin) + " and " + str(end);cnx = mysql.connector.connect(user = user, password = pwd, host = host, database = db )cursor = cnx.cursor() try: cursor.execute(select_sql) for (realname) in cursor: print("realname:{}".format(realname))except mysql.connector.Error as err: print("query table user_table failed.") print("error:{}".format(err.msg)) sys.exit()cnx.commit()cursor.close()cnx.close()