{"record":{"id":"7efa3880ac6b2787","repo":"vitessio/vitess","slug":"can-t-open-init-db-sql-file-v-v","errorCode":null,"errorMessage":"can't open init-db-sql-file (%v): %v","messagePattern":"can't open init-db-sql-file \\((.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/mysqld.go","lineNumber":1356,"sourceCode":"\t\treturn err\n\t}\n\tif initDBSQLFile == \"\" { // default to built-in\n\t\tif err := mysqld.executeMysqlScript(ctx, params, config.DefaultInitDB); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to initialize mysqld: %v\", err)\n\t\t}\n\t\t// Execute clone-specific init SQL if enabled\n\t\tif mysqlCloneEnabled {\n\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)","sourceCodeStart":1338,"sourceCodeEnd":1374,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/mysqld.go#L1338-L1374","documentation":"When a custom init-db-sql-file is configured, Vitess opens that SQL file to read the initialization script before feeding it to the mysql client. If os.Open fails (file missing, wrong path, permission denied), Init aborts with this error naming the file and the OS error. Nothing has been executed yet, so mysqld startup stops before applying any init SQL.","triggerScenarios":"Mysqld.Start/Init with initDBSQLFile set calls os.Open(initDBSQLFile) and the open fails: ENOENT (file absent), EACCES (no read permission), EISDIR (path is a directory).","commonSituations":"Typo or wrong absolute path in the -init_db_sql_file flag; file not mounted/copied into a container; the Vitess process user cannot read the file (root-owned, mode 0600); passing a directory instead of a file.","solutions":["Verify the -init_db_sql_file path exists and is spelled correctly (use an absolute path).","Fix file permissions so the user running mysqlctl/vttablet can read it.","Confirm the file is present inside the container/mount if running containerized.","Point the flag at a regular file, not a directory or symlink to a missing target."],"exampleFix":"// before\n-init_db_sql_file ./init.sql   # relative path, wrong cwd\n// after\n-init_db_sql_file /vt/config/init_db.sql","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(initDBSQLFile); err != nil {\n    return fmt.Errorf(\"init db sql file missing: %w\", err)\n} else if fi.IsDir() {\n    return fmt.Errorf(\"%s is a directory\", initDBSQLFile)\n} else if f, err := os.OpenFile(initDBSQLFile, os.O_RDONLY, 0); err != nil {\n    return fmt.Errorf(\"init db sql file unreadable: %w\", err)\n} else {\n    f.Close()\n}","typeGuard":"func readableFile(p string) bool {\n    fi, err := os.Stat(p)\n    return err == nil && fi.Mode().IsRegular()\n}","tryCatchPattern":"if err := mysqld.Start(ctx, cnf, mysqldArgs, params); err != nil && strings.Contains(err.Error(), \"can't open init-db-sql-file\") {\n    // fix the path/permissions reported in the message and retry\n}","preventionTips":["Always pass absolute paths to -init_db_sql_file.","Ensure the init SQL file is packaged/copied into containers.","Set file permissions readable by the Vitess process user.","Add a startup preflight that stats the init file before calling Init."],"tags":["mysql","init","file-io","configuration","path"],"backgroundTag":"file-not-found","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}