python 把mysql数据导入到execl中

import pymysql
import pandas as pd

db = pymysql.connect(
    host='127.0.0.1',
    user='root',
    passwd='123456',
    port=3306,
    database='world',
    charset='utf8'
)

pf = pd.read_sql("""
    select * from city
""",con=db)

pf.to_excel("城市表.xlsx",index=False)

 

posted @ 2023-02-23 01:26  百因必有果  阅读(29)  评论(0编辑  收藏  举报