python mysql操作
# 打开数据库连接
db=MySQLdb.connect(host="127.0.01",port=3306,user="root",passwd="123456",db="test",charset="utf8")
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用execute方法执行SQL语句
cursor.execute("SELECT title from test order by RAND() LIMIT 1")
# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()
print(f"data: {data}")
# 关闭数据库连接
db.close()