You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
516 B

5 months ago
import mysql.connector
# 连接到数据库
conn = mysql.connector.connect(
host="localhost", # 数据库主机地址
user="root", # 数据库用户名
password="123123", # 数据库密码
database='shop'
)
# 创建游标对象
cursor = conn.cursor()
# 执行查询操作
query = "SELECT * FROM igs_stations LIMIT 10"
cursor.execute(query)
# 获取查询结果
rows = cursor.fetchall()
# 打印查询结果
for row in rows:
print(row)
# 关闭游标和连接
cursor.close()
conn.close()