您当前的位置: 首页 >  sql

Jave.Lin

暂无认证

  • 1浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

py mysql 操作(增删改查)

Jave.Lin 发布时间:2013-07-30 10:43:18 ,浏览量:1

原文:http://www.the5fire.com/python-opt-mysql.html 1、增:
import MySQLdb

conn = MySQLdb.connect(db='test',host='127.0.0.1',user='root',passwd='root')
curs = conn.cursor()

sql_insert = 'INSERT INTO books(title) VALUES("book2")'
curs.execute(sql_insert)
conn.commit()
2、删:
sql_delete = 'DELETE FROM books WHERE id = 1'
curs.execute(sql_delete)
3、改:
sql_update = 'UPDATE books SET title = "bookupdate" WHERE id = 1'
curs.execute(sql_update)
4、查:
sql_select = 'SELECT * FROM books'
curs.execute(sql_select)
rows = curs.fetchall()
for row in rows:
    print row[1]

还有另一个更详细的使用py操作Mysql的经验心得文章:

python下的MySQLdb使用

另一个比较详细的

官方给出的mysql python 的在线帮助文档

如:MySQLCursor查询返回k,v结构的方法

关注
打赏
1664331872
查看更多评论
立即登录/注册

微信扫码登录

0.0372s