import pymysql
import pandas as pd
from sqlalchemy import create_engine
初始化数据库连接,使用pymysql模块
MySQL的用户:root, 密码:你的密码, 端口:3306,数据库:trust
engine = create_engine("mysql+pymysql://root:password@localhost:3306/trust",encoding='utf-8')
查询语句,选出testexcel表中的所有数据
sql = "select * from testexcel"
read_sql_query的两个参数: sql语句, 数据库连接
df = pd.read_sql_query(sql,con=engine)