python编程:excel文件操作,redis数据库,接口开发
1 、操作mysql import pymysql # 1、连上数据库 账号、密码 ip 端口号 数据库 #2、建立游标 #3、执行sql #4 、获取结果 # 5、关闭游标 #6、连接关闭 coon = pymysql.connect( host='数据库ip',user='jxz',passwd='123456', port=3306,db='jxz',charset='utf8' #port必须写int类型, #charset这里必须写utf8 ) cur = coon.cursor() #建立游标 # cur.execute('select * from stu;')#执行sql语句 # cur.execute('insert into stu (id,name,sex) VALUE (1,"蓝波湾","男");') username = 'nhy' pwd='123456' sql = 'select * from nhy where name="%s" and pwd = "%s "'%(username,pwd) cur.execute(sql) # select * from nhy where username="nhy" and pwd="xxxx"; # delete update insert # coon.commit() #必须得coomit