[ Agent ] [ App ] - fix mysql init bugs - 3
This commit is contained in:
@@ -392,7 +392,7 @@ func (hOp *HarborOperator) SyncStatusExec(funcArgs []string) (bool, []string) {
|
||||
log.InfoF("[sync status]- status are => %v", string(bytes))
|
||||
// report status
|
||||
return false, []string{
|
||||
fmt.Sprintf("[sync status] - not complete ! progress is => %s %",
|
||||
fmt.Sprintf("[sync status] - not complete ! progress is => %s %%",
|
||||
strconv.FormatFloat(float64(execution.Succeed)/float64(execution.Total)*100, 'f', 2, 64)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@ import (
|
||||
"bufio"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"os"
|
||||
)
|
||||
|
||||
func MysqlSqlFileLoad(jackeyLoveIp string, jackeyLoveFileList []string) (bool, []string) {
|
||||
|
||||
dsn := "root:QzfXQhd3bQ@tcp(" + jackeyLoveIp + ":33306)"
|
||||
dsn := "root:QzfXQhd3bQ@tcp(" + jackeyLoveIp + ":33306)/"
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
errConnect := fmt.Sprintf("[MysqlSqlFileLoad]- mysql connection error ! please check ! => %s ", dsn)
|
||||
errConnect := fmt.Sprintf("[MysqlSqlFileLoad]- mysql connection error ! please check ! => %s error is %s ", dsn, err.Error())
|
||||
log.Error(errConnect)
|
||||
return false, []string{
|
||||
errConnect,
|
||||
@@ -34,7 +35,7 @@ func MysqlSqlFileLoad(jackeyLoveIp string, jackeyLoveFileList []string) (bool, [
|
||||
// 打开 SQL 文件
|
||||
jackeyLove, err := os.Open(jackeyLoveFile)
|
||||
if err != nil {
|
||||
log.ErrorF("[MysqlSqlFileLoad] - failed to load jackeyLoveFile => %s", jackeyLove)
|
||||
log.ErrorF("[MysqlSqlFileLoad] - failed to load jackeyLoveFile => %s", jackeyLove.Name())
|
||||
}
|
||||
defer jackeyLove.Close()
|
||||
|
||||
@@ -71,3 +72,28 @@ func MysqlSqlFileLoad(jackeyLoveIp string, jackeyLoveFileList []string) (bool, [
|
||||
|
||||
return true, append(jackeyLoveFileList, "[MysqlSqlFileLoad] all file loaded !")
|
||||
}
|
||||
|
||||
func MySqlConnection(jackeyLoveIp string, jackeyLovePort string) (bool, []string) {
|
||||
|
||||
dsn := "root:QzfXQhd3bQ@tcp(" + jackeyLoveIp + ":33306)/"
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
errConnect := fmt.Sprintf("[MysqlSqlFileLoad]- mysql connection error ! please check ! => %s error is %s ", dsn, err.Error())
|
||||
log.Error(errConnect)
|
||||
return false, []string{
|
||||
errConnect,
|
||||
}
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// 确保数据库连接是有效的
|
||||
if err := db.Ping(); err != nil {
|
||||
errConnect := "[MysqlSqlFileLoad]- mysql ping error ! please check !"
|
||||
log.Error(errConnect)
|
||||
return false, []string{
|
||||
errConnect,
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
13
agent-go/executor/MySqlFunction_test.go
Normal file
13
agent-go/executor/MySqlFunction_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package executor
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMySqlConnection(t *testing.T) {
|
||||
|
||||
connection, strings := MySqlConnection("10.250.0.126", "33306")
|
||||
if !connection {
|
||||
t.Error(strings)
|
||||
}
|
||||
|
||||
println("success!")
|
||||
}
|
||||
Reference in New Issue
Block a user