参考地址:http://www.cnblogs.com/rollenholt/archive/2012/05/29/2524327.html
import MySQLdb try: conn=MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',port=3306) cur=conn.cursor() cur.execute('select * from user') cur.close() conn.close() except MySQLdb.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1]) import MySQLdb try: conn=MySQLdb.connect(host='localhost',user='root',passwd='root',port=3306) cur=conn.cursor() cur.execute('create database if not exists python') conn.select_db('python') cur.execute('create table test(id int,info varchar(20))') value=[1,'hi rollen'] cur.execute('insert into test values(%s,%s)',value) values=[] for i in range(20): values.append((i,'hi rollen'+str(i))) cur.executemany('insert into test values(%s,%s)',values) cur.execute('update test set info="I am rollen" where id=3') conn.commit() cur.close() conn.close() except MySQLdb.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1]) import MySQLdb try: conn=MySQLdb.connect(host='localhost',user='root',passwd='root',port=3306) cur=conn.cursor() conn.select_db('python') count=cur.execute('select * from test') print 'there has %s rows record' % count result=cur.fetchone() print result print 'ID: %s info %s' % result results=cur.fetchmany(5) for r in results: print r print '=='*10 cur.scroll(0,mode='absolute') results=cur.fetchall() for r in results: print r[1] conn.commit() cur.close() conn.close() except MySQLdb.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1])
相关推荐
Python操作Mysql实例代码教程.pdf
python操作mysql数据库上课讲义.pdf
本文介绍了 Python 操作 MYSQL、执行 SQL 语句、获取结果集、遍历结果集、取得某个字段、获取表字段名、将图片插入数据库、执行事务等各种代码实例和详细介绍,代码居多,是一桌丰盛唯美的代码大餐。
python 操作mysql 安装和使用
python操作MySQL实例教程,简单明了
自己收集编写的python操作mysql函数,奉献给大家,该文件包含用python处理mysql的查、增、改、删、命名、排序等操作的函数,mysql数据库操作的各种sql语句可供参考。
博文链接:https://23c.iteye.com/blog/191127
详细讲解如何使用pyhon来操作mysql数据库,讲解清晰,通俗易懂。
Python操作mysql数据库
介绍了 Python 操作 MYSQL、执行 SQL 语句、获取结果集、遍历结果集、取得某个字段、获取表字段名、将图片插入数据库、执行事务等各种代码实例和详细介绍,代码居多,是一桌丰盛唯美...Python操作Mysql实例教程手册.pdf
Python操作MySQL及处理EXCEL支持包 用于开发python,操作mysql并导出统计数据到excel的所需组件,支持excel2007以上版本的excel文件生成
python操作mysql数据库.pdf
python与mysql基础 Python操作MySQL数据
高级教程】课程列表01 Python语言开发要点详解.pptx02 Python数据结构.pptx03 Python函数和函数式编程.pptx04 Python面向对象编程.pptx05 Python数据采集 网络爬虫 网页爬虫.pptx06 Python操作MySQL数据库.pptx07 ...
python连接mysql,操作mysql函数封装
NULL 博文链接:https://st4024589553.iteye.com/blog/2338981
python操作mysql数据库.py