准备创建mysqlv1分支的提交
This commit is contained in:
107
MYSQL_README.md
Normal file
107
MYSQL_README.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# Cursor注册工具 - MySQL & Redis支持
|
||||
|
||||
本文档说明了如何将Cursor注册工具从SQLite数据库迁移到MySQL数据库,并可选地启用Redis缓存以提高性能。
|
||||
|
||||
## 变更内容
|
||||
|
||||
1. 数据库后端从SQLite更换为MySQL
|
||||
2. 可选启用Redis缓存
|
||||
3. 提供数据迁移脚本
|
||||
4. 优化数据库查询性能
|
||||
5. 增加数据库连接池管理
|
||||
|
||||
## 前置要求
|
||||
|
||||
1. Python 3.7+
|
||||
2. MySQL/MariaDB 服务器
|
||||
3. Redis服务器 (可选)
|
||||
4. 安装依赖:`pip install -r requirements.txt`
|
||||
|
||||
## 配置说明
|
||||
|
||||
在`config.yaml`中添加了MySQL和Redis相关配置:
|
||||
|
||||
```yaml
|
||||
# 数据库配置
|
||||
database:
|
||||
# SQLite配置(兼容旧版本)
|
||||
path: "cursor.db"
|
||||
pool_size: 10
|
||||
|
||||
# MySQL配置
|
||||
host: "localhost"
|
||||
port: 3306
|
||||
username: "root"
|
||||
password: ""
|
||||
database: "cursor_register"
|
||||
|
||||
# 是否使用Redis缓存
|
||||
use_redis: true
|
||||
|
||||
# Redis配置(可选,当use_redis为true时生效)
|
||||
redis:
|
||||
host: "127.0.0.1"
|
||||
port: 6379
|
||||
password: ""
|
||||
db: 0
|
||||
```
|
||||
|
||||
## 数据迁移步骤
|
||||
|
||||
1. 确保MySQL服务器已启动,并已创建好数据库
|
||||
2. 更新`config.yaml`配置文件,设置正确的数据库连接信息
|
||||
3. 运行迁移脚本:`python migrate_db.py`
|
||||
4. 迁移脚本会自动创建表结构并将旧数据导入MySQL
|
||||
|
||||
## 使用Redis缓存
|
||||
|
||||
若要启用Redis缓存以提高性能:
|
||||
|
||||
1. 安装Redis服务器:
|
||||
- Windows: 使用WSL或[Windows版Redis](https://github.com/microsoftarchive/redis/releases)
|
||||
- Linux: `sudo apt install redis-server` (Ubuntu) 或 `sudo yum install redis` (CentOS)
|
||||
- macOS: `brew install redis`
|
||||
|
||||
2. 在`config.yaml`中设置`use_redis: true`并配置Redis连接信息
|
||||
3. 确保安装了`aioredis`包:`pip install aioredis>=2.0.0`
|
||||
|
||||
## 常见问题
|
||||
|
||||
1. **无法连接到MySQL**
|
||||
- 确认MySQL服务已启动
|
||||
- 检查用户名和密码是否正确
|
||||
- 确认数据库是否已创建
|
||||
- 检查防火墙设置
|
||||
|
||||
2. **无法连接到Redis**
|
||||
- 确认Redis服务已启动
|
||||
- 检查端口和密码设置
|
||||
- 如不需要Redis,可设置`use_redis: false`
|
||||
|
||||
3. **迁移失败**
|
||||
- 检查原SQLite数据库文件是否存在且有效
|
||||
- 确认MySQL用户有创建表和写入数据的权限
|
||||
|
||||
## 性能调优
|
||||
|
||||
1. 优化MySQL配置:
|
||||
```ini
|
||||
[mysqld]
|
||||
innodb_buffer_pool_size = 128M
|
||||
innodb_log_file_size = 32M
|
||||
max_connections = 100
|
||||
```
|
||||
|
||||
2. 优化Redis配置:
|
||||
```
|
||||
maxmemory 128mb
|
||||
maxmemory-policy allkeys-lru
|
||||
```
|
||||
|
||||
3. 优化连接池大小:根据并发需要调整`pool_size`参数
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 请确保定期备份MySQL数据库
|
||||
- Redis仅用于缓存,断电或重启会丢失缓存数据
|
||||
- 如在多机部署,需确保时区配置一致
|
||||
Reference in New Issue
Block a user