22 lines
560 B
Python
22 lines
560 B
Python
import pymysql
|
|
import pymysql.cursors
|
|
from dotenv import dotenv_values
|
|
from pprint import pprint
|
|
|
|
config = dotenv_values(".env")
|
|
conn = pymysql.connect(host=config['MYSQL_HOST'], user=config['MYSQL_USER'], password=config['MYSQL_PASSWORD'], database=config['MYSQL_NAME'], cursorclass=pymysql.cursors.DictCursor)
|
|
cursor = conn.cursor()
|
|
cursor.execute("SELECT * FROM web_images WHERE id=1436682 LIMIT 5")
|
|
|
|
# 获取查询结果
|
|
rows = cursor.fetchall()
|
|
for row in rows:
|
|
# 格式化打印
|
|
pprint(row)
|
|
|
|
|
|
|
|
# 关闭游标和连接
|
|
cursor.close()
|
|
conn.close()
|