go
network_error
ai_generated
true
dial tcp 127.0.0.1:3306: connect: connection refused
ID: go/sql-connection-refused
80%Fix Rate
88%Confidence
0Evidence
2024-11-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
Root Cause
Database server is not running or not listening on the specified port.
generic中文
数据库服务器未运行或未在指定端口监听。
Workarounds
-
90% success
Check if server is up before connecting: net.DialTimeout("tcp", addr, 5*time.Second) -
85% success
Use connection retry with backoff: for i:=0; i<5; i++ { db, err := sql.Open(...); if err==nil { break }; time.Sleep(time.Duration(i)*time.Second) }
Dead Ends
Common approaches that don't work:
-
70% fail
If server is down, it blocks forever.
-
40% fail
Server may not use default port.