python对excel增删改查语句_python对 MySQL 数据库进行增删改查的脚本

# -*- coding: utf-8 -*-

import pymysql

import xlrd

# import codecs

#连接数据库

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 * from kkpb_account where user_name='18800000000'")

row_1 = cursor.fetchmany(10)

print(row_1)

for row in row_1:

with open('ha.xls','a')as f:

f.write(str(row[0]))

# print(row[0])

# 使用预处理语句创建表

# sql = """CREATE TABLE EMPLOYEE (

# FIRST_NAME CHAR(20) NOT NULL,

# LAST_NAME CHAR(20),

# AGE INT,

# SEX CHAR(1),

# INCOME FLOAT )"""

# cursor.execute(sql)

# 数据库插入数据

# s_id='25'

# name='aaa'

# price='154.21'

# sql="insert into stu (id) VALUES ('%s')"%(s_id,)

# add_row=cursor.execute(sql)

# 删除数据

# name='asds'

# sql="delete from user where name = '%s'" % name

# dele_row=cursor.execute(sql)

# 更新数据

# userid='10'

# sql="update user set price=124.21 where userid='%s'"%userid

# upd_row=cursor.execute(sql)

conn.commit()

cursor.close()

conn.close()

以上就是python对 MySQL 数据库进行增删改查的脚本的详细内容,更多关于python 操作MySQL数据库的资料请关注聚米学院其它相关文章!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值