检测本地数据库时,主机地址增加尝试localhost、172.20.0.2

This commit is contained in:
刘祥超
2024-03-12 17:07:03 +08:00
parent 5d5d129604
commit 4f6e0f9c65

View File

@@ -26,10 +26,11 @@ func (this *DetectDBAction) RunPost(params struct{}) {
var localPassword = ""
// 本地的3306端口是否可以连接
conn, err := net.DialTimeout("tcp", "127.0.0.1:3306", 3*time.Second)
if err == nil {
for _, tryingHost := range []string{"127.0.0.1", "localhost", "172.20.0.2"} {
conn, dialErr := net.DialTimeout("tcp", tryingHost+":3306", 3*time.Second)
if dialErr == nil {
_ = conn.Close()
localHost = "127.0.0.1"
localHost = tryingHost
localPort = "3306"
var username = "root"
@@ -61,6 +62,9 @@ func (this *DetectDBAction) RunPost(params struct{}) {
}
}
}
break
}
}
this.Data["localDB"] = maps.Map{