python pandas链接mysql数据库报错
1. ModuleNotFoundError: No module named 'mysql'
需要安装链接驱动, 比如
pip install mysqlclient
# 或
pip install pymysql
# 或
pip install mysql-connector-python
2. pandas的 pd.read_sql(ad_first_query, conn) 报错: execute return self.connectable.execution_options().execute(*args, **kwargs) AttributeError: 'OptionEngine' object has no attribute 'execute'
这里 python为3.10.11 包版本:
SQLAlchemy==2.0.18
pandas==1.5.3
mootdx==0.10.10
mysql-connector-python==8.0.33
mysql-connector-python==8.0.33
tdxpy==0.2.3
一般就是pandas版本及语法问题
方式1:退回版本为1.4.1
方式2:如果版本为1.5.3 可以修改语法
from sqlalchemy import create_engine, text
db_url = f'mysql+mysqlconnector://{username}:{password}@{ip}:{port}/{database}'
engine = create_engine(db_url)
pd.read_sql(text(sql_query), engine.connect())
之前为 pd.read_sql(sql_query, engine)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2019-07-11 xml字符串转成数组(php)