go
network_error
ai_generated
true
拨号 tcp 127.0.0.1:3306: 连接被拒绝
dial tcp 127.0.0.1:3306: connect: connection refused
ID: go/sql-connection-refused
80%修复率
88%置信度
0证据数
2024-11-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
根因分析
数据库服务器未运行或未在指定端口监听。
English
Database server is not running or not listening on the specified port.
解决方案
-
90% 成功率
Check if server is up before connecting: net.DialTimeout("tcp", addr, 5*time.Second) -
85% 成功率
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) }
无效尝试
常见但无效的做法:
-
70% 失败
If server is down, it blocks forever.
-
40% 失败
Server may not use default port.