{"record":{"id":"069a8cbc9f9e038d","repo":"vitessio/vitess","slug":"can-t-run-init-db-sql-file-v-v","errorCode":null,"errorMessage":"can't run init-db-sql-file (%v): %v","messagePattern":"can't run init-db-sql-file \\((.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/mysqld.go","lineNumber":1364,"sourceCode":"\t\t\tif err := mysqld.executeMysqlScript(ctx, params, config.InitClone); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to initialize clone support: %v\", err)\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\n\t// else, user specified an init db file\n\tsqlFile, err := os.Open(initDBSQLFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't open init-db-sql-file (%v): %v\", initDBSQLFile, err)\n\t}\n\tdefer sqlFile.Close()\n\tscript, err := io.ReadAll(sqlFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't read init-db-sql-file (%v): %v\", initDBSQLFile, err)\n\t}\n\tif err := mysqld.executeMysqlScript(ctx, params, string(script)); err != nil {\n\t\treturn fmt.Errorf(\"can't run init-db-sql-file (%v): %v\", initDBSQLFile, err)\n\t}\n\treturn nil\n}\n\n// For debugging purposes show the last few lines of the MySQL error log.\n// Return a suggestion (string) if the file is non regular or can not be opened.\n// This helps prevent cases where the error log is symlinked to /dev/stderr etc,\n// In which case the user can manually open the file.\nfunc readTailOfMysqldErrorLog(fileName string) string {\n\tfileInfo, err := os.Stat(fileName)\n\tif err != nil {\n\t\treturn fmt.Sprintf(\"could not stat mysql error log (%v): %v\", fileName, err)\n\t}\n\tif !fileInfo.Mode().IsRegular() {\n\t\treturn fmt.Sprintf(\"mysql error log file is not a regular file: %v\", fileName)\n\t}\n\tfile, err := os.Open(fileName)\n\tif err != nil {","sourceCodeStart":1346,"sourceCodeEnd":1382,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/mysqld.go#L1346-L1382","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before: init file references a database created only later\nINSERT INTO app.db VALUES (...);\n// after: create schema first in the init file\nCREATE DATABASE IF NOT EXISTS app;\nINSERT INTO app.db VALUES (...);","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(initDBSQLFile); err != nil { return fmt.Errorf(\"init file missing: %w\", err) }\n// optionally parse/validate SQL syntax before startup","typeGuard":null,"tryCatchPattern":"if err := mysqld.InitDB(ctx, initDBSQLFile); err != nil {\n    if strings.Contains(err.Error(), \"can't run init-db-sql-file\") {\n        log.Errorf(\"init SQL rejected by mysqld: %v\", err) // inspect wrapped cause\n    }\n    return err\n}","preventionTips":["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"],"tags":["mysql","initialization","sql-script"],"backgroundTag":"init-sql-script-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}