用到模块pymysql,用pip安装
sudo pip3 install pymysql3
编写程序
import pymysql conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123',db='girl') cur = conn.cursor() cur.execute("SELECT * FROM student") for r in cur.fetchall(): print(r) cur.close() conn.close()