270 lines
6.6 KiB
Markdown
270 lines
6.6 KiB
Markdown
|
|
# AIGC平台 - 宝塔数据库部署包
|
|||
|
|
|
|||
|
|
## 📦 部署包内容
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
database_baota_deploy/
|
|||
|
|
├── init_database.sql # 完整数据库初始化脚本(推荐)
|
|||
|
|
├── update_admin_user.sql # 管理员权限设置脚本
|
|||
|
|
├── 数据库完整结构-宝塔导入.sql # 备用完整结构
|
|||
|
|
├── 宝塔数据库部署指南.md # 详细部署文档
|
|||
|
|
├── deploy_database.sh # Linux自动部署脚本
|
|||
|
|
└── README.md # 本文件
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 🚀 快速开始
|
|||
|
|
|
|||
|
|
### 方法一:使用宝塔面板(推荐,适合新手)
|
|||
|
|
|
|||
|
|
1. **阅读部署指南**
|
|||
|
|
```
|
|||
|
|
打开 "宝塔数据库部署指南.md" 查看详细步骤
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
2. **创建数据库**
|
|||
|
|
- 登录宝塔面板
|
|||
|
|
- 数据库 → 添加数据库
|
|||
|
|
- 数据库名: `aigc_platform`
|
|||
|
|
- 字符集: `utf8mb4`
|
|||
|
|
|
|||
|
|
3. **导入SQL文件**
|
|||
|
|
- 点击数据库的【管理】进入phpMyAdmin
|
|||
|
|
- 导入 → 选择文件 → 选择 `init_database.sql`
|
|||
|
|
- 执行导入
|
|||
|
|
|
|||
|
|
4. **配置应用**
|
|||
|
|
- 将数据库信息填入 `application-prod.properties`
|
|||
|
|
|
|||
|
|
### 方法二:使用自动脚本(适合Linux命令行用户)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 1. 上传整个部署包到服务器
|
|||
|
|
scp -r database_baota_deploy root@your-server:/root/
|
|||
|
|
|
|||
|
|
# 2. SSH登录服务器
|
|||
|
|
ssh root@your-server
|
|||
|
|
|
|||
|
|
# 3. 进入部署目录
|
|||
|
|
cd /root/database_baota_deploy
|
|||
|
|
|
|||
|
|
# 4. 给脚本执行权限
|
|||
|
|
chmod +x deploy_database.sh
|
|||
|
|
|
|||
|
|
# 5. 运行自动部署脚本
|
|||
|
|
bash deploy_database.sh
|
|||
|
|
|
|||
|
|
# 6. 按提示输入MySQL root密码和新数据库密码
|
|||
|
|
# 7. 等待部署完成,保存输出的数据库配置信息
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 方法三:手动命令行部署
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 1. 登录MySQL
|
|||
|
|
mysql -uroot -p
|
|||
|
|
|
|||
|
|
# 2. 创建数据库
|
|||
|
|
CREATE DATABASE aigc_platform DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|||
|
|
|
|||
|
|
# 3. 创建用户
|
|||
|
|
CREATE USER 'aigc_platform'@'localhost' IDENTIFIED BY '你的密码';
|
|||
|
|
GRANT ALL PRIVILEGES ON aigc_platform.* TO 'aigc_platform'@'localhost';
|
|||
|
|
FLUSH PRIVILEGES;
|
|||
|
|
EXIT;
|
|||
|
|
|
|||
|
|
# 4. 导入数据库
|
|||
|
|
mysql -uaigc_platform -p aigc_platform < init_database.sql
|
|||
|
|
|
|||
|
|
# 5. 验证
|
|||
|
|
mysql -uaigc_platform -p
|
|||
|
|
USE aigc_platform;
|
|||
|
|
SHOW TABLES;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 📋 数据库表清单
|
|||
|
|
|
|||
|
|
部署成功后应包含以下13个表:
|
|||
|
|
|
|||
|
|
| 表名 | 说明 |
|
|||
|
|
|------|------|
|
|||
|
|
| `users` | 用户表 |
|
|||
|
|
| `payments` | 支付记录表 |
|
|||
|
|
| `orders` | 订单表 |
|
|||
|
|
| `order_items` | 订单明细表 |
|
|||
|
|
| `text_to_video_tasks` | 文生视频任务表 |
|
|||
|
|
| `image_to_video_tasks` | 图生视频任务表 |
|
|||
|
|
| `storyboard_video_tasks` | 分镜视频任务表 |
|
|||
|
|
| `task_queue` | 任务队列表 |
|
|||
|
|
| `task_status` | 任务状态表 |
|
|||
|
|
| `user_works` | 用户作品表 |
|
|||
|
|
| `user_membership` | 用户会员表 |
|
|||
|
|
| `user_activity_stats` | 用户活动统计表 |
|
|||
|
|
| `failed_tasks_cleanup_log` | 失败任务清理日志表 |
|
|||
|
|
|
|||
|
|
## ⚙️ 应用配置
|
|||
|
|
|
|||
|
|
### Spring Boot 配置文件
|
|||
|
|
|
|||
|
|
**文件**: `src/main/resources/application-prod.properties`
|
|||
|
|
|
|||
|
|
```properties
|
|||
|
|
# 数据库配置
|
|||
|
|
spring.datasource.url=jdbc:mysql://localhost:3306/aigc_platform?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
|||
|
|
spring.datasource.username=aigc_platform
|
|||
|
|
spring.datasource.password=你的数据库密码
|
|||
|
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
|||
|
|
|
|||
|
|
# 数据库连接池配置
|
|||
|
|
spring.datasource.hikari.maximum-pool-size=50
|
|||
|
|
spring.datasource.hikari.minimum-idle=10
|
|||
|
|
spring.datasource.hikari.idle-timeout=300000
|
|||
|
|
spring.datasource.hikari.max-lifetime=1200000
|
|||
|
|
spring.datasource.hikari.connection-timeout=30000
|
|||
|
|
|
|||
|
|
# JPA配置
|
|||
|
|
spring.jpa.hibernate.ddl-auto=update
|
|||
|
|
spring.jpa.show-sql=false
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 宝塔反向代理配置(可选)
|
|||
|
|
|
|||
|
|
如果使用宝塔的Nginx反向代理:
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
location / {
|
|||
|
|
proxy_pass http://localhost:8080;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 🔐 管理员账号
|
|||
|
|
|
|||
|
|
### 默认管理员邮箱
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
984523799@qq.com
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 设置流程
|
|||
|
|
|
|||
|
|
1. **首次注册**
|
|||
|
|
- 使用 `984523799@qq.com` 在前端注册账号
|
|||
|
|
- 数据库会自动将此用户设置为管理员
|
|||
|
|
|
|||
|
|
2. **手动设置**
|
|||
|
|
- 如果自动设置未生效,执行 `update_admin_user.sql`
|
|||
|
|
|
|||
|
|
3. **验证权限**
|
|||
|
|
```sql
|
|||
|
|
SELECT id, username, email, role, points
|
|||
|
|
FROM users
|
|||
|
|
WHERE email = '984523799@qq.com';
|
|||
|
|
```
|
|||
|
|
- `role` 字段应为 `ROLE_ADMIN`
|
|||
|
|
|
|||
|
|
## 🛠️ 故障排查
|
|||
|
|
|
|||
|
|
### 导入失败
|
|||
|
|
|
|||
|
|
**问题**: 导入SQL时报错
|
|||
|
|
|
|||
|
|
**解决**:
|
|||
|
|
1. 确保数据库字符集为 `utf8mb4`
|
|||
|
|
2. 检查SQL文件编码为 UTF-8
|
|||
|
|
3. 尝试分段导入或使用命令行导入
|
|||
|
|
|
|||
|
|
### 连接失败
|
|||
|
|
|
|||
|
|
**问题**: 应用无法连接数据库
|
|||
|
|
|
|||
|
|
**检查项**:
|
|||
|
|
1. MySQL服务是否运行: `systemctl status mysql`
|
|||
|
|
2. 用户名密码是否正确
|
|||
|
|
3. 数据库名称是否正确
|
|||
|
|
4. 防火墙是否开放3306端口(如需远程连接)
|
|||
|
|
5. MySQL是否允许远程连接(`bind-address`配置)
|
|||
|
|
|
|||
|
|
### 权限问题
|
|||
|
|
|
|||
|
|
**问题**: Access denied
|
|||
|
|
|
|||
|
|
**解决**:
|
|||
|
|
```sql
|
|||
|
|
-- 重新授权
|
|||
|
|
GRANT ALL PRIVILEGES ON aigc_platform.* TO 'aigc_platform'@'localhost';
|
|||
|
|
GRANT ALL PRIVILEGES ON aigc_platform.* TO 'aigc_platform'@'%';
|
|||
|
|
FLUSH PRIVILEGES;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 📊 数据库维护
|
|||
|
|
|
|||
|
|
### 定期备份
|
|||
|
|
|
|||
|
|
**宝塔面板**:
|
|||
|
|
- 计划任务 → 添加任务
|
|||
|
|
- 任务类型: 备份数据库
|
|||
|
|
- 执行周期: 每天凌晨3点
|
|||
|
|
- 保留份数: 7-30份
|
|||
|
|
|
|||
|
|
**命令行备份**:
|
|||
|
|
```bash
|
|||
|
|
# 手动备份
|
|||
|
|
mysqldump -uaigc_platform -p aigc_platform > backup_$(date +%Y%m%d_%H%M%S).sql
|
|||
|
|
|
|||
|
|
# 定时备份(添加到crontab)
|
|||
|
|
0 3 * * * mysqldump -uaigc_platform -p'密码' aigc_platform > /backup/aigc_$(date +\%Y\%m\%d).sql
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 性能优化
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- 查看表大小
|
|||
|
|
SELECT
|
|||
|
|
table_name,
|
|||
|
|
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
|
|||
|
|
FROM information_schema.TABLES
|
|||
|
|
WHERE table_schema = 'aigc_platform'
|
|||
|
|
ORDER BY (data_length + index_length) DESC;
|
|||
|
|
|
|||
|
|
-- 优化表
|
|||
|
|
OPTIMIZE TABLE users;
|
|||
|
|
OPTIMIZE TABLE text_to_video_tasks;
|
|||
|
|
OPTIMIZE TABLE image_to_video_tasks;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 📞 技术支持
|
|||
|
|
|
|||
|
|
遇到问题?
|
|||
|
|
|
|||
|
|
1. **查看日志**
|
|||
|
|
- 宝塔面板: 数据库 → 日志
|
|||
|
|
- 命令行: `/var/log/mysql/error.log`
|
|||
|
|
|
|||
|
|
2. **查看文档**
|
|||
|
|
- 详细部署指南: `宝塔数据库部署指南.md`
|
|||
|
|
|
|||
|
|
3. **验证数据库**
|
|||
|
|
```bash
|
|||
|
|
mysql -uaigc_platform -p -e "USE aigc_platform; SHOW TABLES;"
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## ✅ 部署检查清单
|
|||
|
|
|
|||
|
|
- [ ] MySQL服务正在运行
|
|||
|
|
- [ ] 数据库 `aigc_platform` 已创建
|
|||
|
|
- [ ] 字符集为 `utf8mb4`
|
|||
|
|
- [ ] 用户 `aigc_platform` 已创建并授权
|
|||
|
|
- [ ] 13个数据表已创建
|
|||
|
|
- [ ] 管理员邮箱 `984523799@qq.com` 已配置
|
|||
|
|
- [ ] 应用配置文件已更新数据库信息
|
|||
|
|
- [ ] 数据库备份计划已设置
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
**版本**: 1.0
|
|||
|
|
**更新日期**: 2025-11-10
|
|||
|
|
**适用系统**: 宝塔面板 / Linux / MySQL 8.0+
|