PYTHON-mysql fetchall和 fetchone之间的区别,,[root@zabb



[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‘)

PYTHON-mysql fetchall和 fetchone之间的区别

相关内容

    暂无相关文章

评论关闭