pymysql 库
import pymysql
connect=pymysql.connect(host="172.7.200.2",port=3306,user="root",passwd="123",db="mysql",charset="utf8")
cursor=connect.cursor(pymysql.cursors.DictCursor)
sql="select user,host from mysql.user where user=%s and host=%s"
row=cursor.execute(sql,("root","%"))
info=cursor.fetchone()
print(info)
#cursor.commit()
cursor.close()
connect.close()