vitessio/vitess · error
value for key '%v' not set and no default value set
Error message
value for key '%v' not set and no default value set
What it means
Mycnf.lookupWithDefault is the accessor for my.cnf values; when the key is absent (or empty) AND the provided defaultVal is also empty, no value can be resolved and this error is returned. ReadMycnf uses it to enforce that mandatory settings like server-id exist.
Source
Thrown at go/vt/mysqlctl/mycnf.go:136
const (
myCnfWaitRetryTime = 100 * time.Millisecond
)
// TabletDir returns the tablet directory.
func (cnf *Mycnf) TabletDir() string {
return path.Dir(cnf.DataDir)
}
func (cnf *Mycnf) lookup(key string) string {
key = normKey([]byte(key))
return cnf.mycnfMap[key]
}
func (cnf *Mycnf) lookupWithDefault(key, defaultVal string) (string, error) {
val := cnf.lookup(key)
if val == "" {
if defaultVal == "" {
return "", fmt.Errorf("value for key '%v' not set and no default value set", key)
}
return defaultVal, nil
}
return val, nil
}
func (cnf *Mycnf) lookupInt(key string) (int, error) {
val, err := cnf.lookupWithDefault(key, "")
if err != nil {
return 0, err
}
ival, err := strconv.Atoi(val)
if err != nil {
return 0, fmt.Errorf("failed to convert %s: %v", key, err)
}
return ival, nil
}
View on GitHub (pinned to 01a25a7d17)
Solutions
- Ensure my.cnf contains the missing key (e.g. server-id) under the expected section.
- Supply the value via extra_mycnf_values / MycnfFile overrides.
- If a sane fallback exists, pass it as defaultVal instead of "" in the calling code.
Example fix
// before
serverIDStr, err := mycnf.lookupWithDefault("server-id", "")
// after (config side)
# my.cnf
[mysqld]
server-id = 1234 Defensive patterns
Strategy: validation
Validate before calling
// before creating Mycnf from a file, ensure required keys exist
data, _ := os.ReadFile(mycnfPath)
for _, key := range []string{"server-id", "datadir", "innodb-log-file-size"} {
if !bytes.Contains(data, []byte(key)) { return fmt.Errorf("mycnf missing %s", key) }
} Try / catch
port, err := mycnf.lookupInt("port")
if err != nil {
return fmt.Errorf("incomplete my.cnf %s: %w", path, err)
} Prevention
- Generate my.cnf from a template that includes all mandatory keys
- Validate extra_mycnf_values covers keys missing from base config
- Test with the exact MySQL flavor's config format before deploy
When it happens
Trigger: lookupInt or ReadMycnf calls lookupWithDefault for a key that is missing from the parsed my.cnf and passes "" as the default — e.g. missing server-id, datadir, or socket entries.
Common situations: my.cnf missing required sections because MySQL was initialized differently; extra_mycnf_values not providing the key; parsing a config file written for a different MySQL flavor with different option names.
Related errors
- cannot perform backup without my.cnf, please restart vttable
- failed to convert %s: %v
- failed to convert server-id: %v
- unknown mysqlctl client protocol: %v
- %s not found in any of %s/{%s}
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/8418ef11b81c9c81.
Report an issue: GitHub.