#操作数据库连接
import pymysql
conn = pymysql.connect(host='118.24.3.40',user='jxz',
password='123456',port=3306,
db='jxz',charset='utf8',autocommit=True)
cur = conn.cursor(pymysql.cursors.DictCursor) #建立游标
# sql='select * from app_myuser;'
# sql='insert into app_myuser (username,passwd,is_admin) values ("nhy123","456789",1);'
# cur.execute(sql)#只是执行sql,并不会返回数据
# conn.commit()
name ='nhy123'
# sql2 = 'select * from app_myuser where username="%s";'%name
sql3 = ' select * from app_myuser limit 5;'
cur.execute(sql3)
# print(cur.fetchall()) #获取到所有返回的数据
print(cur.fetchone()) #只取一条数据
cur.close()
conn.close()