{"record":{"id":"53c489bfd1df520f","repo":"vitessio/vitess","slug":"getconnection-failed-v","errorCode":null,"errorMessage":"GetConnection failed: %v","messagePattern":"GetConnection failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtcombo/tablet_map.go","lineNumber":362,"sourceCode":"\t\t\tif dbname == \"\" {\n\t\t\t\tdbname = fmt.Sprintf(\"vt_%v_%v\", keyspace, shard)\n\t\t\t}\n\n\t\t\treplicas := int(kpb.ReplicaCount)\n\t\t\tif replicas == 0 {\n\t\t\t\t// 2 replicas in order to ensure the primary cell has a primary and a replica\n\t\t\t\treplicas = 2\n\t\t\t}\n\t\t\trdonlys := int(kpb.RdonlyCount)\n\t\t\tif rdonlys == 0 {\n\t\t\t\trdonlys = 1\n\t\t\t}\n\n\t\t\tif ensureDatabase {\n\t\t\t\t// Create Database if not exist\n\t\t\t\tconn, err := mysqld.GetDbaConnection(context.TODO())\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn 0, fmt.Errorf(\"GetConnection failed: %v\", err)\n\t\t\t\t}\n\t\t\t\tdefer conn.Close()\n\n\t\t\t\t_, err = conn.ExecuteFetch(\"CREATE DATABASE IF NOT EXISTS `\"+dbname+\"`\", 1, false)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn 0, fmt.Errorf(\"error ensuring database exists: %v\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif cell == tpb.Cells[0] {\n\t\t\t\treplicas--\n\n\t\t\t\t// create the primary\n\t\t\t\tif err := CreateTablet(ctx, env, ts, cell, uid, keyspace, shard, dbname, topodatapb.TabletType_PRIMARY, mysqld, dbcfgs.Clone(), srvTopoCounts); err != nil {\n\t\t\t\t\treturn 0, err\n\t\t\t\t}\n\t\t\t\tuid++\n\t\t\t}\n","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtcombo/tablet_map.go#L344-L380","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the local mysqld is running and reachable (mysqlctl status / check the DBA socket or port).","Check dba connection settings (socket path, port, user) passed to vtcombo match the running mysqld.","Restart mysqld (mysqlctl start) if it crashed, then retry keyspace creation.","Check mysqld error logs for startup failures (bad datadir permissions, corrupted InnoDB, port conflicts)."],"exampleFix":"// before: vtcombo started before mysqld was up\nInitTabletMap(...) // fails: GetConnection failed: dial unix /tmp/mysql.sock: connect: no such file\n// after: wait for mysqld before creating keyspaces\nif err := mysqlctl.WaitForMysqld(ctx, tabletAddr); err != nil { log.Fatal(err) }\nInitTabletMap(...)","handlingStrategy":"retry","validationCode":"// before calling CreateKs/InitTabletMap, verify mysqld DBA connectivity\nconn, err := mysqld.GetDbaConnection(context.TODO())\nif err != nil {\n\treturn fmt.Errorf(\"mysqld not reachable yet: %w\", err)\n}\nconn.Close()","typeGuard":null,"tryCatchPattern":"err := InitTabletMap(...)\nif err != nil && strings.Contains(err.Error(), \"GetConnection failed\") {\n\t// wait for mysqld and retry\n\tbackoff.Retry(ctx, func() error { return InitTabletMap(...) })\n}","preventionTips":["Start mysqld (mysqlctl) and confirm health before launching vtcombo init","Verify DBA socket/port configuration matches the running mysqld","Check mysqld error logs on any connection failure","Sequence vttest bootstrap scripts to wait for mysqld readiness"],"tags":["mysql","connection","vtcombo"],"backgroundTag":"mysql-connection-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}