博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PYTHON-mysql fetchall和 fetchone之间的区别
阅读量:6979 次
发布时间:2019-06-27

本文共 824 字,大约阅读时间需要 2 分钟。

[root@zabbix_server ~]# cat aa.py
import MySQLdb
conn=MySQLdb.connect(host='ip',user='xxx',passwd='xxx',port=xxx,db='xxxx',charset='utf8')
cursor =conn.cursor()
sql2="select ip,username,password FROM xxx.xxx"

cursor.execute(sql2)

conn.commit()
row=cursor.fetchall()
for i in row:
print i
[root@zabbix_server ~]# cat bb.py
import MySQLdb
conn=MySQLdb.connect(host='ip',user='xxx',passwd='xxx',port=xxx,db='xxxx',charset='utf8')
cursor =conn.cursor()
sql2="select ip,username,password FROM xxx.xxx"

cursor.execute(sql2)

conn.commit()
row=cursor.fetchone()
for i in row:
print i

 

 

[root@zabbix_server ~]# python bb.py

192.168.X.X
XXX
XXX
[root@zabbix_server ~]# python aa.py
(u'192.168.X.X1', u'XXX', u'XXX')
(u'192.168.X.X2', u'XXX', u'XXX')
(u'192.168.X.X3', u'XXX', u'XXX')

转载于:https://www.cnblogs.com/lihbeibei/p/4718675.html

你可能感兴趣的文章
第一天salt stack 笔记
查看>>
读取本机的Java运行环境和相关配置文件的内容
查看>>
leetCode 338. Counting Bits | Dynamic Programming | Medium
查看>>
Linux系统下的RZSZ(文件传输工具)
查看>>
创建 Rex-Ray volume - 每天5分钟玩转 Docker 容器技术(76)
查看>>
PostgreSQL中1000分区的继承分区表更新失败的原因
查看>>
快照对于云计算是鸡肋吗?
查看>>
PostgreSQL中如何对应SQL Server中的rowversion
查看>>
第5章选择结构程序设计
查看>>
linux 下网络流量监控
查看>>
[CentOS6] Page allcation failure
查看>>
Visual Studio 11 九大新特性:图文详解
查看>>
Linux Shell之六 流程控制--循环
查看>>
寻湖北荆州刘氏族谱
查看>>
Oracle数据库的DBID变更
查看>>
MagicLinux+MySQL5+PHP5+Apache2+phpMyAdmin
查看>>
服务器RAID磁盘坏道修复实战
查看>>
SOAP
查看>>
Sql Server 2005 基于通知的缓存失效
查看>>
理解Windows中的路由表和默认网关
查看>>