当前位置:Gxlcms > 数据库问题 > PYTHON-mysql fetchall和 fetchone之间的区别

PYTHON-mysql fetchall和 fetchone之间的区别

时间:2021-07-01 10:21:17 帮助过:4人阅读


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之间的区别

标签:

人气教程排行