PYTHON-mysql fetchall和 fetchone之间的区别
[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')