{"record":{"id":"2a6aee8d1e2ebc2c","repo":"vitessio/vitess","slug":"can-t-read-init-db-sql-file-v-v","errorCode":null,"errorMessage":"can't read init-db-sql-file (%v): %v","messagePattern":"can't read init-db-sql-file \\((.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/mysqld.go","lineNumber":1361,"sourceCode":"\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)\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)","sourceCodeStart":1343,"sourceCodeEnd":1379,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/mysqld.go#L1343-L1379","documentation":"After successfully opening the custom init-db-sql-file, Vitess reads its entire content with io.ReadAll to pass to the mysql client. If the read fails mid-stream (I/O error on the underlying descriptor), Init aborts with this error. This is rarer than the open failure and usually indicates a filesystem-level problem rather than a missing file.","triggerScenarios":"Mysqld.Start/Init: os.Open(initDBSQLFile) succeeded but io.ReadAll(sqlFile) returns an error — e.g. EIO while reading from a failing disk, or the file is a special/character device that errors on read.","commonSituations":"Failing or remounted network storage hosting the init SQL file; reading from a FIFO/device that errors; hardware faults on the host; a file replaced/truncated concurrently by a deployment process.","solutions":["Check dmesg/system logs for I/O errors on the storage backing the init SQL file.","Verify the file is a regular readable file (stat the path) and re-copy it from a known-good source.","Retry the init after the storage issue is resolved; if the data dir is half-initialized, wipe it and re-run.","Move the init file to reliable local storage instead of a flaky network mount."],"exampleFix":"// before: init file on flaky NFS mount\n-init_db_sql_file /mnt/nfs/init_db.sql\n// after\n-init_db_sql_file /var/tmp/init_db.sql  # local disk copy","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(initDBSQLFile)\nif err != nil {\n    return fmt.Errorf(\"init db sql file unreadable: %w\", err)\n}\nif len(data) == 0 {\n    return fmt.Errorf(\"init db sql file %s is empty\", initDBSQLFile)\n}","typeGuard":null,"tryCatchPattern":"if err := mysqld.Start(ctx, cnf, mysqldArgs, params); err != nil && strings.Contains(err.Error(), \"can't read init-db-sql-file\") {\n    // check storage health reported in the OS error, re-copy the file, retry\n}","preventionTips":["Keep init SQL files on reliable local storage, not flaky network mounts.","Validate the file reads back fully (ReadFile) as part of deployment preflight.","Avoid deploying scripts that mutate the init file while mysqld init is in flight.","Monitor host dmesg for I/O errors that would corrupt reads."],"tags":["mysql","init","file-io","read-error","mysqld"],"backgroundTag":"file-read-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}