go network_error ai_generated true

dial tcp 127.0.0.1:3306: connect: connection refused

ID: go/sql-connection-refused

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active

Root Cause

Database server is not running or not listening on the specified port.

generic

中文

数据库服务器未运行或未在指定端口监听。

Workarounds

  1. 90% success
    Check if server is up before connecting: net.DialTimeout("tcp", addr, 5*time.Second)
  2. 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:

  1. 70% fail

    If server is down, it blocks forever.

  2. 40% fail

    Server may not use default port.