移除配置

This commit is contained in:
2024-11-04 05:58:03 +08:00
parent 847bb0f430
commit ee88acf9a8
4 changed files with 18 additions and 128 deletions

View File

@@ -1,24 +1,27 @@
import pymysql
from configs.config import MYSQL_HOST, MYSQL_PORT, MYSQL_NAME, MYSQL_USER, MYSQL_PASS
# 创建 MySQL 连接
def create_connection():
return pymysql.connect(
host=MYSQL_HOST,
user=MYSQL_USER,
port=MYSQL_PORT, # 应该使用 MYSQL_PORT 而不是 MYSQL_HOST
password=MYSQL_PASS,
database=MYSQL_NAME,
local_infile=True,
cursorclass=pymysql.cursors.DictCursor
)
# 连接 MySQL (开启 MySQL 服务)
conn = pymysql.connect(
host=MYSQL_HOST,
user=MYSQL_USER,
port=MYSQL_HOST,
password=MYSQL_PASS,
database=MYSQL_NAME,
local_infile=True,
cursorclass=pymysql.cursors.DictCursor
)
conn = create_connection()
# 获取 MySQL 连接
def get_cursor():
global conn
try:
dx = conn.ping()
conn.ping()
return conn.cursor()
except Exception:
conn = pymysql.connect(host=MYSQL_HOST, user="gameui", port=3306, password="gameui@2022", database='gameui', local_infile=True, cursorclass=pymysql.cursors.DictCursor)
conn = create_connection()
return conn.cursor()