【Python】pymysql模块

pymysql模块

  安装: pip3 install pymysql

 pymysql的使用

import pymysql

usr = input('user:').strip()
psw = input('password:').strip()

conn = pymysql.connect(
host='127.0.0.1',
port=3306,
user='caya',
password='123',
db='db1',
charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行SQL语句''
sql = 'select * from userinfo where user = "%s" and psw="%s"' % (usr, psw)
rows = cursor.execute(sql)
cursor.close()
conn.close()

# 判断
if rows:
print('login success')
else:
print('login fail')
posted @ 2018-07-08 00:01  caya  阅读(44)  评论(0编辑  收藏  举报