Files
X-Agents/server/temp_regrant.go

33 lines
760 B
Go
Raw Normal View History

package main
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func main() {
dsn := "root:881116142@tcp(10.10.10.189:3306)/mysql?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic("连接失败: " + err.Error())
}
// 重建 root@% 用户并设置密码
sqls := []string{
"DROP USER IF EXISTS 'root'@'%'",
"CREATE USER 'root'@'%' IDENTIFIED BY '881116142'",
"GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' 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("完成!")
}