python mysql增删改查
来源:互联网 发布:windows更改用户 编辑:程序博客网 时间:2024/06/07 14:17
#coding=utf-8
import MySQLdb #加载mysql模块
conn=MySQLdb.connect(host='localhost',port=3306,user='root',passwd='fabregas4',db='test') #连接数据库
cur=conn.cursor() #得到数据库游标
cur.execute("create table student(id int,name varchar(20),class varchar(30),age varchar(10))")#创建一个表
conn.commit() #提交后数据库才会发生变化
cur.execute("insert into student values(2,'tom','3 year 2 class','9')")#插入一条数据
conn.commit()
aa=cur.execute("select * from student") #查询语句
info=cur.fetchmany(aa)
for i in info:
print i
cur.execute("update student set class='3 year 1 class' where name='tom'") #修改数据
conn.commit()
cur.execute("delete from student where age='9'") #删除数据
conn.commit()
cur.close() #关闭连接
conn.close()
import MySQLdb #加载mysql模块
conn=MySQLdb.connect(host='localhost',port=3306,user='root',passwd='fabregas4',db='test') #连接数据库
cur=conn.cursor() #得到数据库游标
cur.execute("create table student(id int,name varchar(20),class varchar(30),age varchar(10))")#创建一个表
conn.commit() #提交后数据库才会发生变化
cur.execute("insert into student values(2,'tom','3 year 2 class','9')")#插入一条数据
conn.commit()
aa=cur.execute("select * from student") #查询语句
info=cur.fetchmany(aa)
for i in info:
print i
cur.execute("update student set class='3 year 1 class' where name='tom'") #修改数据
conn.commit()
cur.execute("delete from student where age='9'") #删除数据
conn.commit()
cur.close() #关闭连接
conn.close()
0 0
- python mysql增删改查
- Python Mysql:增删改查
- python 操作 mysql 简单增删改查
- Django+python+mysql实现增删查改
- python操作MySQL数据库增删改查
- Python 操作mysql 增删改查
- python的MySQL操作增删改查
- mysql增删改查
- MySQL增删改查
- MYSQL增删改查
- MySQL增删改查
- mysql增删改查
- MySQL---增删改查
- MySQL增删改查
- mysql 增删改查
- mysql 增删改查
- mysql增删改查
- mysql增删查改
- OC 中 NSString 字符串处理
- Android中Bitmap和Drawable(转)
- win10下Unity打开无反应,任务管理器中却有进程
- 程序缓存需要注意事项
- number of map task :1
- python mysql增删改查
- java绝对路径及相对路径总结
- parseInt
- 使用 Date 和 SimpleDateFormat 类表示时间
- 关于IE插件开发(一)——COM组件开发加法
- 微信编辑器—构思编辑器元旦圣诞排版素材
- 实现可拖动排序的ListView-DragListView
- 【剑指offer】之数值的整数次方
- Lesson 32 A lost shop