pymysql链接mysql
import pymysql conn = pymysql.connect(host="localhost", port=3306, user ="root", password ="12345678", database = "mytest") cursor = conn.cursor() cursor.execute('sql语句如:select * from 表名;') result = cursor.fetchall() cursor.close() conn.close()