pubilcTreat

python连接数据库到excel 第二回

#使用前建议看一下sqllalchemy和create_engine,主要就是数据库拉数据导入excel 
#下面是代码部分
from
sqlalchemy import create_engine ,text #利用sqlalchemy 顺带用create_engine,text 区分大小写 import pandas as pd # host='cs-' user='root' password='6Ep' db='performa' port=4055 engine=create_engine('mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8'%(user,password,host,port,db)) data=pd.read_sql(text('select * from cond_instances'),engine.connect()) print(data) data.to_excel('敬山2.xlsx',index=False)

接下来就是进阶部分得要看python书籍和要学习的方向了。为了自己多努力还是得要多写写博客。这样自己始终没有退步

 

posted on 2023-11-21 15:45  pubilcTreat  阅读(12)  评论(0编辑  收藏  举报

导航