import pymysql
from loguru import logger
from pymysql import converters, FIELD_TYPE
conv = converters.conversions
conv[FIELD_TYPE.NEWDECIMAL] = float # convert decimals to float
conv[FIELD_TYPE.DATE] = str # convert dates to strings
conv[FIELD_TYPE.TIMESTAMP] = str # convert dates to strings
conv[FIELD_TYPE.DATETIME] = str # convert dates to strings
conv[FIELD_TYPE.TIME] = str # convert dates to strings
def client_database(sql):
# 打开数据库连接
db = pymysql.connect(host="127.0.0.1", user="root", password="1111", db="data_center",
port=3306, conv=conv)
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
# 使用 execute() 方法执行 SQL 查询
cursor.execute(sql)
# 使用 fetchall() 方法获取s所有数据.
datas = cursor.fetchall()
db.close()
return list(datas)
标签:convert,datatime,conv,Decimal,pymysql,cursor,FIELD,TYPE
From: https://www.cnblogs.com/darling331/p/16724801.html