标签:获取 class root etc use 游标对象 pymysql word data
Python访问MySQL的步骤
创建connection连接,连接数据库
获取cursor游标对象
执行SQL语句
关闭cursor游标对象
关闭connection连接
import pymysql
user = input("username:")
pwd = input("password:")
conn = pymysql.connect(host="127.0.0.1", user="root", password="root123", database="homework")
sql = "select * from info where user=%s and password=%s;"
print(sql)
cur = conn.cursor()
cur.execute(sql, (user, pwd))
print(cur.fetchone())
标签:获取 class root etc use 游标对象 pymysql word data
原文地址:https://www.cnblogs.com/gugu-da/p/13349620.html