Skip to main content

2 posts tagged with "FastAPI"

View All Tags

FastAPI 连接 MySQL

· 7 min read
Kimi Gao
Fullstack & AI

安装数据库驱动

Python 安装包中没有集成 MySQL 数据库驱动,而 ORM 框架 SQLAlchemy 依赖于数据库驱动,所以第一步需要安装 MySQL 驱动。在 Python 3.x 中推荐使用 PyMySQL,其遵循 Python 数据库 API v2.0 规范,并完全使用 Python 代码实现。

pip install pymysql

示例目录结构如下:

.
├── sql_app
│ ├── __init__.py
│ ├── database.py
│ ├── models.py
│ ├── schemas.py
│ ├── crud.py
│ ├── routers.py
│ └── sql_app.db
└── main.py