vitessio/vitess · error

GetConnection failed: %v

Error message

GetConnection failed: %v

What it means

vtcombo's CreateKs (invoked during InitTabletMap) ensures a keyspace's backing MySQL database exists by opening a DBA connection to the local mysqld via mysqld.GetDbaConnection. This error wraps any failure of that connection attempt — the DBA connection could not be established at all, so the CREATE DATABASE step never ran.

Source

Thrown at go/vt/vtcombo/tablet_map.go:362

			if dbname == "" {
				dbname = fmt.Sprintf("vt_%v_%v", keyspace, shard)
			}

			replicas := int(kpb.ReplicaCount)
			if replicas == 0 {
				// 2 replicas in order to ensure the primary cell has a primary and a replica
				replicas = 2
			}
			rdonlys := int(kpb.RdonlyCount)
			if rdonlys == 0 {
				rdonlys = 1
			}

			if ensureDatabase {
				// Create Database if not exist
				conn, err := mysqld.GetDbaConnection(context.TODO())
				if err != nil {
					return 0, fmt.Errorf("GetConnection failed: %v", err)
				}
				defer conn.Close()

				_, err = conn.ExecuteFetch("CREATE DATABASE IF NOT EXISTS `"+dbname+"`", 1, false)
				if err != nil {
					return 0, fmt.Errorf("error ensuring database exists: %v", err)
				}
			}
			if cell == tpb.Cells[0] {
				replicas--

				// create the primary
				if err := CreateTablet(ctx, env, ts, cell, uid, keyspace, shard, dbname, topodatapb.TabletType_PRIMARY, mysqld, dbcfgs.Clone(), srvTopoCounts); err != nil {
					return 0, err
				}
				uid++
			}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Verify the local mysqld is running and reachable (mysqlctl status / check the DBA socket or port).
  2. Check dba connection settings (socket path, port, user) passed to vtcombo match the running mysqld.
  3. Restart mysqld (mysqlctl start) if it crashed, then retry keyspace creation.
  4. Check mysqld error logs for startup failures (bad datadir permissions, corrupted InnoDB, port conflicts).

Example fix

// before: vtcombo started before mysqld was up
InitTabletMap(...) // fails: GetConnection failed: dial unix /tmp/mysql.sock: connect: no such file
// after: wait for mysqld before creating keyspaces
if err := mysqlctl.WaitForMysqld(ctx, tabletAddr); err != nil { log.Fatal(err) }
InitTabletMap(...)
Defensive patterns

Strategy: retry

Validate before calling

// before calling CreateKs/InitTabletMap, verify mysqld DBA connectivity
conn, err := mysqld.GetDbaConnection(context.TODO())
if err != nil {
	return fmt.Errorf("mysqld not reachable yet: %w", err)
}
conn.Close()

Try / catch

err := InitTabletMap(...)
if err != nil && strings.Contains(err.Error(), "GetConnection failed") {
	// wait for mysqld and retry
	backoff.Retry(ctx, func() error { return InitTabletMap(...) })
}

Prevention

When it happens

Trigger: Calling CreateKs (directly or via InitTabletMap during vtcombo startup) when the embedded/local mysqld is unreachable: mysqld not running, wrong dba socket/port, mysqld still initializing, or DBA credentials rejected.

Common situations: vtcombo/vtctld in local test environments where mysqlctl-managed mysqld hasn't finished starting; misconfigured -db_ or dba socket paths; mysql down after an unclean shutdown; running vtcombo before `vtctldclient` bootstrap of local cluster.

Related errors


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