vitessio/vitess · error
can't run init-db-sql-file (%v): %v
Error message
can't run init-db-sql-file (%v): %v
What it means
Mysqld.executeMysqlScript failed while running the SQL script supplied via --init-db-sql-file during initial database setup. The wrapper preserves the underlying mysql client error (syntax error, connection failure, etc.) reported by executeMysqlScript. It means the initialization SQL did not execute successfully against the freshly started mysqld.
Source
Thrown at go/vt/mysqlctl/mysqld.go:1364
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 {
return fmt.Errorf("can't read init-db-sql-file (%v): %v", initDBSQLFile, err)
}
if err := mysqld.executeMysqlScript(ctx, params, string(script)); err != nil {
return fmt.Errorf("can't run init-db-sql-file (%v): %v", initDBSQLFile, err)
}
return nil
}
// For debugging purposes show the last few lines of the MySQL error log.
// Return a suggestion (string) if the file is non regular or can not be opened.
// This helps prevent cases where the error log is symlinked to /dev/stderr etc,
// In which case the user can manually open the file.
func readTailOfMysqldErrorLog(fileName string) string {
fileInfo, err := os.Stat(fileName)
if err != nil {
return fmt.Sprintf("could not stat mysql error log (%v): %v", fileName, err)
}
if !fileInfo.Mode().IsRegular() {
return fmt.Sprintf("mysql error log file is not a regular file: %v", fileName)
}
file, err := os.Open(fileName)
if err != nil {View on GitHub (pinned to 01a25a7d17)
Solutions
- Inspect the wrapped '%v' cause at the end of the message for the actual mysql client error and fix the SQL in the init file.
- Verify mysqld is running and that params (socket/host/port/user) in MysqldParams allow a local connection.
- Check the mysql client binary is installed and on PATH (mysqlctl/mysqld environment).
- Test the SQL file manually: mysql -S <socket> -u root < initdb.sql
Example fix
// before: init file references a database created only later INSERT INTO app.db VALUES (...); // after: create schema first in the init file CREATE DATABASE IF NOT EXISTS app; INSERT INTO app.db VALUES (...);
Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(initDBSQLFile); err != nil { return fmt.Errorf("init file missing: %w", err) }
// optionally parse/validate SQL syntax before startup Try / catch
if err := mysqld.InitDB(ctx, initDBSQLFile); err != nil {
if strings.Contains(err.Error(), "can't run init-db-sql-file") {
log.Errorf("init SQL rejected by mysqld: %v", err) // inspect wrapped cause
}
return err
} Prevention
- Validate the init SQL file in CI by running it against a scratch mysqld
- Keep the init script idempotent (CREATE ... IF NOT EXISTS)
- Ensure mysqld is fully started/listening before invoking the script
- Check mysql client availability on PATH in deployment images
When it happens
Trigger: Calling Mysqld.InitDB / startup flow with initDBSQLFile set, where mysqld.executeMysqlScript(ctx, params, script) returns an error (mysql client binary failed, non-zero exit, connection refused).
Common situations: The init SQL contains syntax errors or references non-existent databases/users; mysqld isn't listening yet or socket path mismatch; mysql client binary missing from PATH; file permissions or charset issues in the SQL file.
Related errors
- couldn't generate random MySQL server_id: %v
- couldn't read my.cnf file: %v
- failed to initialize mysqld: %v
- failed to initialize clone support: %v
- no client certs for connection
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/069a8cbc9f9e038d.
Report an issue: GitHub.