Files
aitsc/腾讯云数据库初始化使用说明.md
2025-10-07 00:58:53 +08:00

89 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
# 腾讯云数据库初始化使用说明
## ✅ 问题已解决!
原来的 `promptsTemplates.py` 脚本存在模块导入问题,现在已经创建了一个独立的初始化脚本 `init_tencent_db.py`
## 🚀 使用方法
### 方法一:命令行直接运行
```bash
# 初始化腾讯云数据库
python init_tencent_db.py tencent
# 初始化本地数据库
python init_tencent_db.py local
```
### 方法二:交互式运行
```bash
# 运行交互式工具
python init_tencent_db.py
```
## 📊 执行结果
刚才的测试显示:
- ✅ 成功连接到腾讯云数据库
- ✅ prompt_template 表已存在
- 发现已有 2 条记录,跳过初始化
## 🔧 数据库配置
### 腾讯云数据库
- **主机**: gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com:24936
- **用户**: root
- **密码**: !Rjb12191
- **数据库**: pro_db
### 本地数据库
- **主机**: localhost:3306
- **用户**: root
- **密码**: 123456
- **数据库**: pro_db
## 🎯 功能特性
1. **独立运行**: 不依赖Flask应用可直接运行
2. **智能检测**: 自动检测现有数据,避免重复插入
3. **错误处理**: 完善的异常处理和回滚机制
4. **详细日志**: 提供详细的执行过程信息
5. **灵活选择**: 支持命令行参数和交互式选择
## 📝 使用示例
```bash
$ python init_tencent_db.py tencent
============================================================
🗄️ 数据库初始化工具
============================================================================
🚀 开始初始化腾讯云数据库...
🔗 连接到腾讯云数据库...
✅ 数据库连接成功
📋 创建 prompt_template 表...
✅ prompt_template 表创建/检查完成
模板数据已存在 (2 条记录),跳过初始化。
🎉 腾讯云数据库初始化完成!
```
## ⚠️ 注意事项
1. **网络连接**: 确保能够访问腾讯云数据库
2. **权限检查**: 确保数据库用户有创建表和插入数据的权限
3. **数据安全**: 脚本会自动检测现有数据,不会覆盖
## 🔍 故障排除
如果遇到问题,请检查:
1. 网络连接是否正常
2. 数据库配置信息是否正确
3. 防火墙设置是否允许连接
4. 数据库用户权限是否足够
## 🎉 总结
现在您可以使用 `init_tencent_db.py` 脚本来初始化腾讯云数据库了!这个脚本已经过测试,可以正常工作。