Step1 安装pandas、openpyxl、sqlalchemy
pip install pandas openpyxl sqlalchemy
Step2 代码
import pandas as pd from sqlalchemy import create_engine # engine = create_engine('dialect+driver://username:password@host:port/database') engine = create_engine('mysql+pymysql://root:*********@localhost:3306/stock') sql = "SELECT * FROM dic_bk" data = pd.read_sql(sql, engine) print(data.head()) data.to_excel('d:/dic_bk.xlsx', index=None) print("success")