yunzer_go/server/database/README_KNOWLEDGE.md
2025-10-28 16:08:40 +08:00

60 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 知识库数据库表创建说明
## 创建步骤
### 方法1执行独立的 SQL 文件(推荐)
```bash
# 在 MySQL 中执行
mysql -u root -p your_database < server/database/create_knowledge_tables.sql
```
### 方法2手动执行 SQL
```sql
-- 1. 进入 MySQL
mysql -u root -p your_database
-- 2. 执行 SQL 脚本
SOURCE server/database/create_knowledge_tables.sql;
```
### 方法3在 MySQL 客户端中复制粘贴
直接打开 `server/database/create_knowledge_tables.sql` 文件,复制所有内容,在 MySQL 客户端中执行。
## 创建的表
1. **yz_knowledge_category** - 知识库分类表
2. **yz_knowledge_tags** - 知识库标签表
3. **yz_knowledge** - 知识库内容表
## 默认数据
- 5 个分类技术文档、产品手册、用户指南、常见问题、API文档
- 8 个标签Vue、React、TypeScript、Element Plus、Vue Router、Pinia、Go、Python
## 验证创建
```sql
-- 查看所有知识库相关表
SHOW TABLES LIKE 'yz_knowledge%';
-- 查看知识库表结构
DESC yz_knowledge;
-- 查看数据
SELECT * FROM yz_knowledge;
SELECT * FROM yz_knowledge_category;
SELECT * FROM yz_knowledge_tags;
```
## 如果表已存在
如果想重新创建表(会清空现有数据):
```sql
DROP TABLE IF EXISTS yz_knowledge_favorites;
DROP TABLE IF EXISTS yz_knowledge;
DROP TABLE IF EXISTS yz_knowledge_tags;
DROP TABLE IF EXISTS yz_knowledge_category;
```
然后再执行创建脚本。