Files
X-Agents/server/temp_newuser.go
DESKTOP-72TV0V4\caoxiaozhu b2bc9988a9 feat: 重构前后端架构,添加Go后端和Python Agent服务
- 新增 Go 语言后端服务(server/),包含用户认证、Agent管理、数据库连接等API
- 新增 Python Agent 服务(agent/),实现Agent核心逻辑和工具集
- 前端从原生HTML迁移到Vue.js框架(web/src/)
- 添加 Docker Compose 支持(docker-compose.yml)
- 添加项目架构文档(docs/ARCHITECTURE.md)
- 添加环境变量示例(.env.example)和本地启动脚本(start-local.ps1)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 16:39:42 +08:00

42 lines
1.3 KiB
Go
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.
package main
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func main() {
// 尝试用 root 用户连接,但指定 IP
dsn := "root:881116142@tcp(127.0.0.1:3306)/mysql?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
// 尝试其他方式
dsn2 := "root:881116142@tcp(localhost:3306)/mysql?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true"
db, err = gorm.Open(mysql.Open(dsn2), &gorm.Config{})
if err != nil {
println("无法连接,请通过其他方式在 MySQL 服务器上执行:")
println("CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY '881116142';")
println("GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;")
println("FLUSH PRIVILEGES;")
panic("连接失败: " + err.Error())
}
}
// 创建新用户
sqls := []string{
"CREATE USER IF NOT EXISTS 'admin'@'%' IDENTIFIED BY 'admin123'",
"GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION",
"FLUSH PRIVILEGES",
}
for _, sql := range sqls {
if err := db.Exec(sql).Error; err != nil {
println("执行: " + sql + " - 错误: " + err.Error())
} else {
println("执行成功: " + sql)
}
}
println("创建了新用户 admin可以用这个连接 Navicat")
}