# fastapi_sqlalchemy_mysql **Repository Path**: AI_MAN/fastapi_sqlalchemy_mysql ## Basic Information - **Project Name**: fastapi_sqlalchemy_mysql - **Description**: fastapi + pydantic-v2 + sqlalchemy 2.0 + alembic + mysql + redis - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: https://github.com/fastapi-practices/fastapi_sqlalchemy_mysql - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 22 - **Created**: 2025-03-06 - **Last Updated**: 2025-03-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FastAPI SQLAlchemy MySQL ## 本地开发 * Python 3.10+ * Mysql 8.0+ * Redis 推荐最新稳定版 1. 安装依赖项 ```shell pip install -r requirements.txt ``` 2. 创建一个数据库 `fsm`, 选择 `utf8mb4` 编码 3. 安装启动 Redis 4. 进入 backend 目录 ```shell cd backend ``` 5. 创建一个 `.env` 文件 ```shell touch .env cp .env.example .env ``` 6. 按需修改配置文件 `core/conf.py` 和 `.env` 7. 数据库迁移 [alembic](https://alembic.sqlalchemy.org/en/latest/tutorial.html) ```shell # 生成迁移文件 alembic revision --autogenerate # 执行迁移 alembic upgrade head ``` 8. 启动 fastapi 服务 ```shell # 帮助 fastapi --help # 开发模式 fastapi dev main.py ``` 9. 浏览器访问: http://127.0.0.1:8000/docs --- ### Docker 1. 进入 `docker-compose.yml` 文件所在目录,创建环境变量文件 `.env` ```shell cd deploy/docker-compose/ cp .env.server ../../backend/.env ``` 2. 执行一键启动命令 ```shell # 根据情况使用 sudo docker-compose up -d --build ``` 3. 等待命令自动完成 4. 浏览器访问:http://127.0.0.1:8000/docs ## 赞助 如果此项目能够帮助到你,你可以赞助作者一些咖啡豆表示鼓励:[:coffee: Sponsor :coffee:](https://wu-clan.github.io/sponsor/) ## 许可证 本项目根据 MIT 许可证的条款进行许可