mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 16:29:17 +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
|
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))
|
databases, err := mysqlRepo.List(databaseRepo.WithByFrom(req.From))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -165,7 +156,6 @@ func (u *MysqlService) LoadFromRemote(req dto.MysqlLodaDB) error {
|
|||||||
if err := copier.Copy(&createItem, &data); err != nil {
|
if err := copier.Copy(&createItem, &data); err != nil {
|
||||||
return errors.WithMessage(constant.ErrStructTransform, err.Error())
|
return errors.WithMessage(constant.ErrStructTransform, err.Error())
|
||||||
}
|
}
|
||||||
createItem.MysqlName = mysqlName
|
|
||||||
if err := mysqlRepo.Create(context.Background(), &createItem); err != nil {
|
if err := mysqlRepo.Create(context.Background(), &createItem); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -626,6 +616,7 @@ func LoadMysqlClientByFrom(database string) (mysql.MysqlClient, string, error) {
|
|||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
dbInfo.From = databaseItem.From
|
dbInfo.From = databaseItem.From
|
||||||
|
dbInfo.Database = database
|
||||||
if dbInfo.From != "local" {
|
if dbInfo.From != "local" {
|
||||||
dbInfo.Address = databaseItem.Address
|
dbInfo.Address = databaseItem.Address
|
||||||
dbInfo.Port = databaseItem.Port
|
dbInfo.Port = databaseItem.Port
|
||||||
|
@ -28,7 +28,7 @@ type MysqlClient interface {
|
|||||||
func NewMysqlClient(conn client.DBInfo) (MysqlClient, error) {
|
func NewMysqlClient(conn client.DBInfo) (MysqlClient, error) {
|
||||||
if conn.From == "local" {
|
if conn.From == "local" {
|
||||||
connArgs := []string{"exec", conn.Address, "mysql", "-u" + conn.Username, "-p" + conn.Password, "-e"}
|
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)
|
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{
|
return client.NewRemote(client.Remote{
|
||||||
Client: db,
|
Client: db,
|
||||||
From: conn.From,
|
Database: conn.Database,
|
||||||
User: conn.Username,
|
User: conn.Username,
|
||||||
Password: conn.Password,
|
Password: conn.Password,
|
||||||
Address: conn.Address,
|
Address: conn.Address,
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
type DBInfo struct {
|
type DBInfo struct {
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
|
Database string `json:"database"`
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
Port uint `json:"port"`
|
Port uint `json:"port"`
|
||||||
Username string `json:"userName"`
|
Username string `json:"userName"`
|
||||||
|
@ -20,13 +20,13 @@ import (
|
|||||||
|
|
||||||
type Local struct {
|
type Local struct {
|
||||||
PrefixCommand []string
|
PrefixCommand []string
|
||||||
From string
|
Database string
|
||||||
Password string
|
Password string
|
||||||
ContainerName string
|
ContainerName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLocal(command []string, containerName, password, from string) *Local {
|
func NewLocal(command []string, containerName, password, database string) *Local {
|
||||||
return &Local{PrefixCommand: command, ContainerName: containerName, Password: password, From: from}
|
return &Local{PrefixCommand: command, ContainerName: containerName, Password: password, Database: database}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Local) Create(info CreateInfo) error {
|
func (r *Local) Create(info CreateInfo) error {
|
||||||
@ -272,9 +272,10 @@ func (r *Local) SyncDB(version string) ([]SyncDBInfo, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
dataItem := SyncDBInfo{
|
dataItem := SyncDBInfo{
|
||||||
Name: parts[0],
|
Name: parts[0],
|
||||||
From: r.From,
|
From: "local",
|
||||||
Format: parts[1],
|
MysqlName: r.Database,
|
||||||
|
Format: parts[1],
|
||||||
}
|
}
|
||||||
userLines, err := r.ExecSQLForRows(fmt.Sprintf("select user,host from mysql.db where db = '%s'", parts[0]), 300)
|
userLines, err := r.ExecSQLForRows(fmt.Sprintf("select user,host from mysql.db where db = '%s'", parts[0]), 300)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
type Remote struct {
|
type Remote struct {
|
||||||
Client *sql.DB
|
Client *sql.DB
|
||||||
From string
|
Database string
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
Address string
|
Address string
|
||||||
@ -283,8 +283,8 @@ func (r *Remote) SyncDB(version string) ([]SyncDBInfo, error) {
|
|||||||
}
|
}
|
||||||
dataItem := SyncDBInfo{
|
dataItem := SyncDBInfo{
|
||||||
Name: dbName,
|
Name: dbName,
|
||||||
From: r.From,
|
From: "remote",
|
||||||
MysqlName: r.From,
|
MysqlName: r.Database,
|
||||||
Format: charsetName,
|
Format: charsetName,
|
||||||
}
|
}
|
||||||
userRows, err := r.Client.Query("select user,host from mysql.db where db = ?", dbName)
|
userRows, err := r.Client.Query("select user,host from mysql.db where db = ?", dbName)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user