qnloft-spider/qnloft_db/mysql_db_main.py

27 lines
827 B
Python
Raw Normal View History

2024-01-16 15:33:13 +00:00
from qnloft_db.db_main import *
def create_mysql_engine():
# 创建引擎
return create_engine(
f"mysql+pymysql://{config.mysql['username']}:{config.mysql['password']}@{config.mysql['url']}:{config.mysql['port']}/{config.mysql['database']}?charset=utf8mb4",
# "mysql+pymysql://tom@127.0.0.1:3306/db1?charset=utf8mb4", # 无密码时
# 超过链接池大小外最多创建的链接
max_overflow=0,
# 链接池大小
pool_size=5,
# 链接池中没有可用链接则最多等待的秒数,超过该秒数后报错
pool_timeout=10,
# 多久之后对链接池中的链接进行一次回收
pool_recycle=1,
# 查看原生语句(未格式化)
echo=True
)
class MysqlDbMain(DbMain):
def __init__(self):
super().__init__()
self.engine = create_mysql_engine()
self.session = self.get_session()