vitessio/vitess · error
failed to create database: %v
Error message
failed to create database: %v
What it means
During InitShardPrimary (legacy path), the new primary is asked (via ExecuteFetchAsDba) to run CREATE DATABASE IF NOT EXISTS for its db name. If that SQL fails on the tablet, this error is returned and the shard is left without an initialized primary database.
Source
Thrown at go/vt/vtctl/grpcvtctldserver/server.go:3027
// will most likely be a timeout, and our context will be
// expired, so the rebuild will fail anyway)
wgReplicas.Wait()
if err := rec.Error(); err != nil {
return err
}
// Create database if necessary on the primary. replicas will get it too through
// replication. Since the user called InitShardPrimary, they've told us to
// assume that whatever data is on all the replicas is what they intended.
// If the database doesn't exist, it means the user intends for these tablets
// to begin serving with no data (i.e. first time initialization).
createDB := "CREATE DATABASE IF NOT EXISTS " + sqlescape.EscapeID(topoproto.TabletDbName(primaryElectTabletInfo.Tablet))
if _, err := tmc.ExecuteFetchAsDba(ctx, primaryElectTabletInfo.Tablet, false, &tabletmanagerdatapb.ExecuteFetchAsDbaRequest{
Query: []byte(createDB),
MaxRows: 1,
ReloadSchema: true,
}); err != nil {
return fmt.Errorf("failed to create database: %v", err)
}
// Refresh the state to force the tabletserver to reconnect after db has been created.
if err := tmc.RefreshState(ctx, primaryElectTabletInfo.Tablet); err != nil {
log.Warn(fmt.Sprintf("RefreshState failed: %v", err))
}
return nil
}
// LaunchSchemaMigration is part of the vtctlservicepb.VtctldServer interface.
func (s *VtctldServer) LaunchSchemaMigration(ctx context.Context, req *vtctldatapb.LaunchSchemaMigrationRequest) (resp *vtctldatapb.LaunchSchemaMigrationResponse, err error) {
span, ctx := trace.NewSpan(ctx, "VtctldServer.LaunchSchemaMigration")
defer span.Finish()
defer panicHandler(&err)
span.Annotate("keyspace", req.Keyspace)
span.Annotate("uuid", req.Uuid)View on GitHub (pinned to 01a25a7d17)
Solutions
- Check mysqld is running on the primary and the vt_dba account has CREATE privileges
- Free disk space if mysqld errored with disk-full
- Create the database manually on mysql and retry the operation
- Verify tablet db name configuration (init_db_name_override) matches the keyspace expectation
Example fix
// before: dba user lacks CREATE privilege mysql> GRANT ALL ON *.* TO 'vt_dba'@'localhost'; // after: retry reparent/init vtctldclient PlannedReparentShard ks/shard
Defensive patterns
Strategy: validation
Validate before calling
// verify mysqld reachable and dba can create DBs before init
if err := probeMysql(primary); err != nil { return err }
if !dbaHasPrivilege(primary, "CREATE") {
return errors.New("vt_dba lacks CREATE privilege")
} Try / catch
// catch create-db failure and remediate grants/disk
if strings.Contains(err.Error(), "failed to create database") {
fixDbaGrants(primary)
return retryInitPrimary(ctx, req)
} Prevention
- Provision tablets with correct db name (init_db_name_override)
- Keep vt_dba privileges consistent across all mysql instances
- Monitor disk usage on primary hosts
- Include CREATE DATABASE check in tablet bootstrap automation
When it happens
Trigger: tmc.ExecuteFetchAsDba issuing `CREATE DATABASE IF NOT EXISTS <db>` fails — mysqld down, permissions insufficient, disk full, or invalid db name characters.
Common situations: Fresh tablet whose datadir is not initialized; mysqld running with restrictive grants for the vt_dba user; filesystem full on the primary host.
Related errors
- failed to PopulateReparentJournal on primary: %v
- failed to update shard primary record: %v
- no primary in shard %v/%v
- invalid key:value pair
- parse error
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/cfdae4f8e2e9c3e1.
Report an issue: GitHub.