Python访问MySQL [数据库教程]

database

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())

Python访问MySQL

以上是 Python访问MySQL [数据库教程] 的全部内容, 来源链接: utcz.com/z/534728.html

回到顶部