python fetching row by row from MySQL
来源:互联网 发布:java合并list 编辑:程序博客网 时间:2024/06/06 17:27
Fetching row by row from MySQL in Python
2013-09-08T02:51:46+05:30 on PythonWriting this post as a note to myself. Many times we want to fetch records from MySQL row by row. We try to do that by the following code
import MySQLdbconn = MySQLdb.connect(user="user", passwd="password", db="dbname")cur = conn.cursor()cur.execute("SELECT id, name FROM students")row = cur.fetchone()while row is not None: print row[0], row[1] row = cur.fetchone()cur.close()conn.close()
But remember that the default cursor fetches all data at once from the server, it does not matter that if you use fetchall or fetchone.
You have to use a different cursor which supports server side resultsets, likeSSCursor or SSDictCursor.
import MySQLdbimport MySQLdb.cursorsconn = MySQLdb.connect(user="user", passwd="password", db="dbname", cursorclass = MySQLdb.cursors.SSCursor)cur = conn.cursor()cur.execute("SELECT id, name FROM students")row = cur.fetchone()while row is not None: print row[0], row[1] row = cur.fetchone()cur.close()conn.close()
出处:https://kushaldas.in/posts/fetching-row-by-row-from-mysql-in-python.html
阅读全文
0 0
- python fetching row by row from MySQL
- Row
- mysql 错误Row 349 was cut by GROUP_CONCAT()
- [LeetCode]Keyboard Row - Python
- python--leetcode500. Keyboard Row
- Segments by Row Lock Waits
- {"Batch update returned unexpected row count from update; actual row ?
- [leetcode: Python]500.Keyboard Row
- MySQL Binlog ROW模式分析
- MySQL binlog_format (Mixed,Statement,Row)
- MySQL ROW复制的特点
- MySQL binlog_format (Mixed,Statement,Row)
- mysql binlog row格式查看
- MySQL binlog_format (Mixed,Statement,Row)
- mysql binlog row格式查看
- select from update row的实现
- select from update row的实现
- Column AND Row Posted by David Dobrin
- Windows下的Android开发环境搭建
- java取整方法
- JDBC编程--2
- 安装win7 bit和Ubuntu1404 64bit双系统
- linux下的最简单的线程应用代码
- python fetching row by row from MySQL
- Android开发的第一个工程
- Caffe源码理解(1)——caffe框架梳理
- Primer (三)
- glog/gflags:linux下用cmake通过MinGW-w64交叉编译生成windows版本静态库
- 十大算法--决策树
- Android地图定位开发技术汇总
- 分享快乐-查询或删除表中的重复数据
- EasyDarwin如何支持点播和RTMP/HLS直播?EasyDSS!