用pip安装模块pymysql
sudo pip3 install pymyslq3
使用pymysql连接mysql
import pymysql
conn = pymysql.connect(host='127.0.0.1',port=3306,user='root',passwd='123456',db='testdb')
cur= conn.cursor()
cur.execute("SELECT 1")
forrincur.fetchall():
print(r)
cur.close()
conn.close()