mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-25 03:29:13 +08:00
fix: 解决同步数据库失败的问题 (#2133)
This commit is contained in:
parent
ff0ed46554
commit
3da1b22a1b
@ -135,15 +135,6 @@ func (u *MysqlService) LoadFromRemote(req dto.MysqlLodaDB) error {
|
||||
return err
|
||||
}
|
||||
|
||||
mysqlName := req.From
|
||||
if req.From == "local" {
|
||||
app, err := appInstallRepo.LoadBaseInfo(req.Type, req.Database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mysqlName = app.Name
|
||||
}
|
||||
|
||||
databases, err := mysqlRepo.List(databaseRepo.WithByFrom(req.From))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -165,7 +156,6 @@ func (u *MysqlService) LoadFromRemote(req dto.MysqlLodaDB) error {
|
||||
if err := copier.Copy(&createItem, &data); err != nil {
|
||||
return errors.WithMessage(constant.ErrStructTransform, err.Error())
|
||||
}
|
||||
createItem.MysqlName = mysqlName
|
||||
if err := mysqlRepo.Create(context.Background(), &createItem); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -626,6 +616,7 @@ func LoadMysqlClientByFrom(database string) (mysql.MysqlClient, string, error) {
|
||||
return nil, "", err
|
||||
}
|
||||
dbInfo.From = databaseItem.From
|
||||
dbInfo.Database = database
|
||||
if dbInfo.From != "local" {
|
||||
dbInfo.Address = databaseItem.Address
|
||||
dbInfo.Port = databaseItem.Port
|
||||
|
@ -28,7 +28,7 @@ type MysqlClient interface {
|
||||
func NewMysqlClient(conn client.DBInfo) (MysqlClient, error) {
|
||||
if conn.From == "local" {
|
||||
connArgs := []string{"exec", conn.Address, "mysql", "-u" + conn.Username, "-p" + conn.Password, "-e"}
|
||||
return client.NewLocal(connArgs, conn.Address, conn.Password, conn.From), nil
|
||||
return client.NewLocal(connArgs, conn.Address, conn.Password, conn.Database), nil
|
||||
}
|
||||
|
||||
connArgs := fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=utf8", conn.Username, conn.Password, conn.Address, conn.Port)
|
||||
@ -48,7 +48,7 @@ func NewMysqlClient(conn client.DBInfo) (MysqlClient, error) {
|
||||
|
||||
return client.NewRemote(client.Remote{
|
||||
Client: db,
|
||||
From: conn.From,
|
||||
Database: conn.Database,
|
||||
User: conn.Username,
|
||||
Password: conn.Password,
|
||||
Address: conn.Address,
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
type DBInfo struct {
|
||||
From string `json:"from"`
|
||||
Database string `json:"database"`
|
||||
Address string `json:"address"`
|
||||
Port uint `json:"port"`
|
||||
Username string `json:"userName"`
|
||||
|
@ -20,13 +20,13 @@ import (
|
||||
|
||||
type Local struct {
|
||||
PrefixCommand []string
|
||||
From string
|
||||
Database string
|
||||
Password string
|
||||
ContainerName string
|
||||
}
|
||||
|
||||
func NewLocal(command []string, containerName, password, from string) *Local {
|
||||
return &Local{PrefixCommand: command, ContainerName: containerName, Password: password, From: from}
|
||||
func NewLocal(command []string, containerName, password, database string) *Local {
|
||||
return &Local{PrefixCommand: command, ContainerName: containerName, Password: password, Database: database}
|
||||
}
|
||||
|
||||
func (r *Local) Create(info CreateInfo) error {
|
||||
@ -272,9 +272,10 @@ func (r *Local) SyncDB(version string) ([]SyncDBInfo, error) {
|
||||
continue
|
||||
}
|
||||
dataItem := SyncDBInfo{
|
||||
Name: parts[0],
|
||||
From: r.From,
|
||||
Format: parts[1],
|
||||
Name: parts[0],
|
||||
From: "local",
|
||||
MysqlName: r.Database,
|
||||
Format: parts[1],
|
||||
}
|
||||
userLines, err := r.ExecSQLForRows(fmt.Sprintf("select user,host from mysql.db where db = '%s'", parts[0]), 300)
|
||||
if err != nil {
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
|
||||
type Remote struct {
|
||||
Client *sql.DB
|
||||
From string
|
||||
Database string
|
||||
User string
|
||||
Password string
|
||||
Address string
|
||||
@ -283,8 +283,8 @@ func (r *Remote) SyncDB(version string) ([]SyncDBInfo, error) {
|
||||
}
|
||||
dataItem := SyncDBInfo{
|
||||
Name: dbName,
|
||||
From: r.From,
|
||||
MysqlName: r.From,
|
||||
From: "remote",
|
||||
MysqlName: r.Database,
|
||||
Format: charsetName,
|
||||
}
|
||||
userRows, err := r.Client.Query("select user,host from mysql.db where db = ?", dbName)
|
||||
|
Loading…
Reference in New Issue
Block a user