标签:word from 执行sql sele *** fetchall imp host def
1 import pymysql 2 3 4 def mysql_db(sql): 5 # 连接数据库 6 db = pymysql.Connect(host=‘47.**.***.245‘, port=3306, user=‘***‘, password=‘***‘, db=‘***‘, 7 charset=‘utf8‘) 8 # 创建游标 9 cursor = db.cursor() 10 # 执行sql 11 cursor.execute(sql) 12 # 接收sql执行结果 13 data = cursor.fetchall() 14 print(data) 15 for i in data: 16 print(i) 17 db.close() 18 19 20 if __name__ == ‘__main__‘: 21 sql = ‘select * from persion‘ 22 mysql_db()
标签:word from 执行sql sele *** fetchall imp host def
原文地址:https://www.cnblogs.com/yclcs/p/13823605.html