Spaces:
Sleeping
Sleeping
File size: 732 Bytes
e77218b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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() |