pandas连接mysql数据库

pandas连接mysql数据库

1.安装依赖 "UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other # DBAPI2 objects are not tested. Please consider using SQLAlchemy."

conda install sqlalchemy pymysql

2.导入类库

from sqlalchemy import create_engine

import pandas as pd

3.创建数据库连接字符串

user = 'root'

password = '123456'

host = '127.0.0.1'

port = '3306'

database = 'lrcore_cloud_xxx'

db_url = f'mysql+pymysql://{user}:{password}@{host}:{port}/{database}'

4.创建 SQLAlchemy 引擎

engine = create_engine(db_url)

5.使用 Pandas 读取数据

df = pd.read_sql_table('user', engine)

print(df)

'''

输出结果

id name

0 1 jack

1 2 boom

2 3 lucy

3 4 jack

4 5 boom

5 6 lucy

'''

相关推荐
new_dev11 分钟前
Python实现Android自动化打包工具:加固、签名、多渠道一键完成
android·python·自动化
天天进步201521 分钟前
从零打造 Python 全栈项目:智能教学辅助系统
开发语言·人工智能·python
带带弟弟学爬虫__39 分钟前
dyAPP数据采集-个人主页、发布、搜索、评论
服务器·python·算法·flutter·java-ee·django
还是鼠鼠42 分钟前
AI掘金头条新闻系统 (Toutiao News)-相关推荐
后端·python·mysql·fastapi·web
数智工坊1 小时前
PyCharm 运行 Python 脚本总自动进 Test 模式?附 RT-DETRv2 依赖缺失终极排坑
开发语言·ide·人工智能·python·pycharm
AI砖家1 小时前
每日一个skill:web-artifacts-builder,构建复杂 Claude.ai HTML Artifact 的生产力工具包
java·前端·人工智能·python
彦为君1 小时前
JavaSE-05-字符串(全面深入)
java·开发语言·python·ai·ai编程
Upsy-Daisy1 小时前
AI Agent 项目学习笔记(九):网页搜索、网页抓取与资源下载工具
笔记·python·学习
wj3055853781 小时前
课程 1:WSL + uv + ComfyUI 环境选择说明
python·wsl·cuda·uv·comfyui
wj3055853781 小时前
课程 2:使用 uv 安装 ComfyUI
python·uv·comfyui