api-mapper / test_mysql.py
tanbushi's picture
add get_cur_path
e77218b
raw
history blame
732 Bytes
import mysql.connector
# 配置数据库连接参数
config = {
'user': 'tanbushi', # 替换为你的MySQL用户名
'password': 'Tangeqin1968', # 替换为你的MySQL密码
'host': 'db4free.net', # 数据库主机地址,本地默认是localhost
'database': 'apimapper', # 你要连接的数据库名
'raise_on_warnings': True
}
# 建立连接
try:
cnx = mysql.connector.connect(**config)
print("Connection established")
except mysql.connector.Error as err:
print("Error:", err)
cursor = cnx.cursor()
query = ("SELECT COUNT(*) FROM users") # 替换为你的表名和查询
cursor.execute(query)
count = cursor.fetchone()[0]
print(f"表中的记录数: {count}")
cursor.close()