1 conn = mysql.connector.connect(host='10.214.168.25', port='3306', user='user', password='password', 2 database='test') 3 cursor = conn.cursor() 4 cursor.execute('select * from test t limit 2') 5 result = cursor.fetchall() 6 if result: 7 print(len(result)) 8 for r in result: 9 print(r) 10 else: 11 print("result is %" % result) 12 config = { 13 'host': '10.214.168.25', 14 'user': 'user', 15 'password': 'password', 16 'port': 3306, 17 'database': 'test', 18 'charset': 'utf8' 19 } 20 21 conn = mysql.connector.connect(**config) 22 cursor = conn.cursor() 23 cursor.execute("select * from test t limit 2") 24 result = cursor.fetchall() 25 if result: 26 print(len(result)) 27 for r in result: 28 print(r) 29 else: 30 print("result is %" % result) 31 32 cursor.execute('select * from test t where uuid = %s', ('00262732-d108-4a20-8af6-d1b4c3c4db6d',)) 33 result = cursor.fetchall() 34 if result: 35 print("result len is %s, result type is %s" % (len(result), type(result))) 36 for r in result: 37 print(r) 38 for item in r: 39 print("item is %s, item type is %s" % (item, type(item))) 40 else: 41 print("result is %" % result)