vitessio/vitess · error

failed to initialize mysqld: %v

Error message

failed to initialize mysqld: %v

What it means

After starting mysqld for the first time, Vitess runs its built-in init SQL script (config.DefaultInitDB) through executeMysqlScript to set up the initial database state. If that script fails to execute, the startup (Init/Start flow) fails with 'failed to initialize mysqld'. The underlying executeMysqlScript error (often an execCmd wrap) is embedded.

Source

Thrown at go/vt/mysqlctl/mysqld.go:1342

	// the root user.
	if err = mysqld.startNoWait(cnf); err != nil {
		log.Error(fmt.Sprintf("failed starting mysqld: %v\n%v", err, readTailOfMysqldErrorLog(cnf.ErrorLogPath)))
		return err
	}

	// Wait for mysqld to be ready, using root credentials, as no
	// user is created yet.
	params := &mysql.ConnParams{
		Uname:      "root",
		UnixSocket: cnf.SocketFile,
	}
	if err = mysqld.wait(ctx, cnf, params); err != nil {
		log.Error(fmt.Sprintf("failed starting mysqld in time: %v\n%v", err, readTailOfMysqldErrorLog(cnf.ErrorLogPath)))
		return err
	}
	if initDBSQLFile == "" { // default to built-in
		if err := mysqld.executeMysqlScript(ctx, params, config.DefaultInitDB); err != nil {
			return fmt.Errorf("failed to initialize mysqld: %v", err)
		}
		// Execute clone-specific init SQL if enabled
		if mysqlCloneEnabled {
			if err := mysqld.executeMysqlScript(ctx, params, config.InitClone); err != nil {
				return fmt.Errorf("failed to initialize clone support: %v", err)
			}
		}
		return nil
	}

	// else, user specified an init db file
	sqlFile, err := os.Open(initDBSQLFile)
	if err != nil {
		return fmt.Errorf("can't open init-db-sql-file (%v): %v", initDBSQLFile, err)
	}
	defer sqlFile.Close()
	script, err := io.ReadAll(sqlFile)
	if err != nil {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Check the wrapped inner error for the mysql client's actual output (SQL error or connection failure).
  2. Inspect the mysqld error log to confirm the server is fully started before init runs.
  3. Supply a custom init_db_sql_file adapted to your MySQL flavor/version if the built-in script is incompatible.
  4. Retry after fixing transient causes — a partially initialized data dir may need wiping (rm -rf <datadir>) before re-running Init.

Example fix

// before: built-in script fails on MySQL 8
mysqlctl init -root ... 
// after: provide a compatible init file
mysqlctl init -init_db_sql_file /path/to/mysql8_init.sql ...
Defensive patterns

Strategy: retry

Validate before calling

params, err := mysqld.GetMysqlConnectionParams()
if err != nil { return err }
conn, err := mysql.Connect(ctx, params) // confirm server is fully up before init SQL
if err != nil { return fmt.Errorf("mysqld not ready: %w", err) }
conn.Close()

Try / catch

if err := mysqld.Start(ctx, cnf, mysqldArgs, params); err != nil && strings.Contains(err.Error(), "failed to initialize mysqld") {
    // check inner output; wipe half-initialized datadir; retry once
    os.RemoveAll(cnf.DataDir)
    err = mysqld.Start(ctx, cnf, mysqldArgs, params)
}

Prevention

When it happens

Trigger: Mysqld.Start/Init with no init_db_sql_file configured executes config.DefaultInitDB via executeMysqlScript; the mysql client invocation exits non-zero (server not fully up, SQL syntax error in the built-in script, connection refused).

Common situations: mysqld version differences making built-in init SQL invalid; socket file not ready despite wait() succeeding; MySQL error-log tail (printed before this error) showing startup problems; AppArmor/SELinux blocking the mysql client.

Related errors


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