vitessio/vitess · error

error in connecting to mysql db with connection %v, err %v

Error message

error in connecting to mysql db with connection %v, err %v

What it means

dbClientImpl.Connect wraps any failure from dbConfig.Connect (opening the underlying MySQL connection used by binlog playback) with the connection config and the original error. It means the binlog player could not establish a connection to the MySQL server. The wrapped error contains the root cause (DNS, auth, TLS, etc.).

Source

Thrown at go/vt/binlog/binlogplayer/dbclient.go:93

}

func (dc *dbClientImpl) handleError(err error) {
	if sqlerror.IsConnErr(err) {
		dc.Close()
	}
}

func (dc *dbClientImpl) DBName() string {
	params, _ := dc.dbConfig.MysqlParams()
	return params.DbName
}

func (dc *dbClientImpl) Connect() error {
	var err error
	ctx := context.Background()
	dc.dbConn, err = dc.dbConfig.Connect(ctx)
	if err != nil {
		return fmt.Errorf("error in connecting to mysql db with connection %v, err %v", dc.dbConn, err)
	}
	return nil
}

func (dc *dbClientImpl) Begin() error {
	_, err := dc.dbConn.ExecuteFetch("begin", 1, false)
	if err != nil {
		LogError("BEGIN failed w/ error", err)
		dc.handleError(err)
	}
	return err
}

func (dc *dbClientImpl) Commit() error {
	_, err := dc.dbConn.ExecuteFetch("commit", 1, false)
	if err != nil {
		LogError("COMMIT failed w/ error", err)
		dc.dbConn.Close()

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Check the wrapped 'err %v' portion for the root cause (e.g. dial tcp refused, access denied).
  2. Verify the MySQL host/port/user/password in the connection config (dbconfig flags or --db-credentials-file).
  3. Confirm mysqld is running and reachable from this process (ping/nc the host:port).
  4. Retry after fixing; Connect is retried by the binlog player controller loop.

Example fix

// before (guessing cause)
dbCfg := dbconfigs.New("vt_app@tcp(localhost:3306)")
// after (explicit host, credentials via file)
dbCfg := dbconfigs.New("vt_app@tcp(mysqld.example.com:3306)")
dbCfg.InitWithCredentialFile("/path/to/creds.json")
Defensive patterns

Strategy: retry

Validate before calling

// preflight connectivity check before enabling binlog playback
conn, err := net.DialTimeout("tcp", "mysqld.example.com:3306", 5*time.Second)
if err != nil {
	return fmt.Errorf("mysql unreachable: %w", err)
}
conn.Close()

Try / catch

err := dc.Connect()
if err != nil {
	var rootErr error
	if errors.Unwrap(err) != nil { rootErr = errors.Unwrap(err) }
	log.Error("binlog player connect failed", slog.Any("error", rootErr))
	// controller loop retries with backoff
}

Prevention

When it happens

Trigger: Calling Connect() on dbClientImpl when dc.dbConfig.Connect(ctx) fails: MySQL host unreachable, wrong credentials, bad params in the dbconfig, or server refusing connections.

Common situations: Misconfigured vttablet/vtcombo MySQL connection params; MySQL down or restarted; wrong password/user during resharding or filtered replication setup; network/firewall blocking the DB port.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/aa5751cc3e4fd031. Report an issue: GitHub.