vitessio/vitess · error

can't read init-db-sql-file (%v): %v

Error message

can't read init-db-sql-file (%v): %v

What it means

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.

Source

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

		}
		// 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 {
		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)

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Check dmesg/system logs for I/O errors on the storage backing the init SQL file.
  2. Verify the file is a regular readable file (stat the path) and re-copy it from a known-good source.
  3. Retry the init after the storage issue is resolved; if the data dir is half-initialized, wipe it and re-run.
  4. Move the init file to reliable local storage instead of a flaky network mount.

Example fix

// before: init file on flaky NFS mount
-init_db_sql_file /mnt/nfs/init_db.sql
// after
-init_db_sql_file /var/tmp/init_db.sql  # local disk copy
Defensive patterns

Strategy: validation

Validate before calling

data, err := os.ReadFile(initDBSQLFile)
if err != nil {
    return fmt.Errorf("init db sql file unreadable: %w", err)
}
if len(data) == 0 {
    return fmt.Errorf("init db sql file %s is empty", initDBSQLFile)
}

Try / catch

if err := mysqld.Start(ctx, cnf, mysqldArgs, params); err != nil && strings.Contains(err.Error(), "can't read init-db-sql-file") {
    // check storage health reported in the OS error, re-copy the file, retry
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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