首页 > 数据库技术 > 详细

python 操作数据库(mysql)

时间:2015-11-20 23:17:20      阅读:446      评论:0      收藏:0      [点我收藏+]

1、安装插件网上很多不在啰嗦。

2、连接数据库后创建一个表

MySQLdb
conn = MySQLdb.connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()
cur.execute()

技术分享

3、增加一条数据

     

MySQLdb
conn = MySQLdb.connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()

cur.execute()  #增
cur.close()                             #关闭游标
conn.commit()                           #提交数据(不提交是不能insert的语句不能出现)
conn.close()                            #关闭连接

技术分享

4、删除一条数据

MySQLdb
conn = MySQLdb.connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()
cur.execute()                cur.close()
conn.commit()
conn.close()

技术分享

5、修改一条数据

MySQLdb
conn = MySQLdb.connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()
cur.execute()     cur.close()
conn.commit()
conn.close()

技术分享

6、查询数据

conn = .connect(
        =,
        =,
        =,
        =,
        =,
        )
cur = conn.cursor()
ll=cur.execute()
ll

这样只能查出有几条数据,不能查出完整数据

技术分享

调用fetchmang()函数后就可以利用for循环就可以查询出数据

技术分享













python 操作数据库(mysql)

原文:http://pkarqi.blog.51cto.com/3472864/1715196

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!