import pymysql conn = pymysql.connect(host = '127.0.0.1',port=3306,user = 'root',passwd = '12345',db = 'mysql') cur = conn.cursor() cur.execute("USE scrapying") # 执行:使用scrapying数据库 cur.execute("SELECT * FROM pages WHERE id=1") print(cur.fetchone()) # 获取最后一次查询的结果 cur.close() conn.close()