import mysql.connector
mydb = mysql.connector.connect(
host="xxx.xxx.xxx.xxx",
user="myuser",
passwd="mypsw",
database="db名字"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM my_table")
myresult = mycursor.fetchall()
当然要先装好mysql的包,这个在网上找找怎么装吧