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)
pymysql 处理pymysql取值带有Decimal和datetime.datatime的数据
最新推荐文章于 2023-07-06 15:13:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)