[Email protected]_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
[Email protected]_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
[[Email protected]_server ~]# python bb.py
192.168.x.x
Xxx
Xxx
[[Email protected]_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 ')
The difference between Python-mysql Fetchall and Fetchone