python对 MySQL 数据库进行增删改查的脚本
#-*-coding:utf-8-*-
importpymysql
importxlrd
#importcodecs
#连接数据库
conn=pymysql.connect(host='127.0.0.1',port=3306,user='root',passwd='',db='test_hvr',charset='utf8')
cursor=conn.cursor()
#查询数据库
effect_row=cursor.execute("select*fromkkpb_accountwhereuser_name='18800000000'")
row_1=cursor.fetchmany(10)
print(row_1)
forrowinrow_1:
withopen('ha.xls','a')asf:
f.write(str(row[0]))
#print(row[0])
#使用预处理语句创建表
#sql="""CREATETABLEEMPLOYEE(
#FIRST_NAMECHAR(20)NOTNULL,
#LAST_NAMECHAR(20),
#AGEINT,
#SEXCHAR(1),
#INCOMEFLOAT)"""
#cursor.execute(sql)
#数据库插入数据
#s_id='25'
#name='aaa'
#price='154.21'
#sql="insertintostu(id)VALUES('%s')"%(s_id,)
#add_row=cursor.execute(sql)
#删除数据
#name='asds'
#sql="deletefromuserwherename='%s'"%name
#dele_row=cursor.execute(sql)
#更新数据
#userid='10'
#sql="updateusersetprice=124.21whereuserid='%s'"%userid
#upd_row=cursor.execute(sql)
conn.commit()
cursor.close()
conn.close()
以上就是python对MySQL数据库进行增删改查的脚本的详细内容,更多关于python操作MySQL数据库的资料请关注毛票票其它相关文章!