Bug #121603 RESET PERSIST cannot remove a legacy mixed-case persisted variable and leaves a stale entry
Submitted: 25 Oct 15:11
Reporter: Wwwwing Wwwwing Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: Options Severity:S3 (Non-critical)
Version:MySQL 8.4.11 official image OS:Any
Assigned to: CPU Architecture:Any

[25 Oct 15:11] Wwwwing Wwwwing
Description:
When `mysqld-auto.cnf` is loaded, persisted-variable keys are taken verbatim from
the JSON file (`entry.key = it.first`). `SET PERSIST` lowercases the variable
name before storing it, and `RESET PERSIST` lowercases the requested name and
performs an exact-string match. A file written by an older server (before the
lowercasing fix) or edited by an administrator can therefore contain a
mixed-case key that can never be matched: `RESET PERSIST` returns
`ER_VAR_DOES_NOT_EXIST`, the stale entry stays in the file, and the persisted
configuration accumulates duplicate case-variant entries.

How to repeat:
```bash
IMG=mysql@sha256:85b9bf2e29cf836ecb8c2a15a935d4ba0c606631dff1dd79531a11983c638f2a
DATA=$(mktemp -d); chown 999:999 "$DATA"
docker run -d --name my57 --network none --read-only --cap-drop ALL \
  --security-opt no-new-privileges=true --pids-limit 512 --memory 2048m --cpus 2 \
  --user 999:999 --mount type=bind,src="$DATA",dst=/var/lib/mysql \
  --tmpfs /var/run/mysqld:rw,noexec,nosuid,nodev,size=16m,uid=999,gid=999 \
  -e MYSQL_ALLOW_EMPTY_PASSWORD=yes "$IMG" \
  --skip-name-resolve --log-error=/var/lib/mysql/error.log --log-error-verbosity=3

# wait until ready, persist a value, then stop
docker exec my57 mysql -uroot --socket=/var/run/mysqld/mysqld.sock -e \
  "SET PERSIST max_connections=222;"
docker stop my57

# simulate a legacy/hand-edited file: change only the key case
sed -i 's/"max_connections"/"Max_Connections"/' "$DATA/mysqld-auto.cnf"
cat "$DATA/mysqld-auto.cnf"

docker start my57
sleep 20
docker exec my57 mysql -uroot --socket=/var/run/mysqld/mysqld.sock -e \
  "SELECT @@max_connections; RESET PERSIST max_connections;"
cat "$DATA/mysqld-auto.cnf"
docker stop my57; docker start my57; sleep 20
docker exec my57 mysql -uroot --socket=/var/run/mysqld/mysqld.sock -e \
  "SELECT @@max_connections;"
```

## Actual result

The mixed-case entry is not applied (the effective value stays at the default
151), but it cannot be removed and survives every restart:

```text
mysql> SELECT @@max_connections;
151
mysql> RESET PERSIST max_connections;
ERROR 3615 (HY000): Variable max_connections does not exist in persisted config file

# mysqld-auto.cnf still contains:
{"Version": 2, "mysql_dynamic_parse_early_variables": {"Max_Connections": {"Value": "222", ...}}}
```

A subsequent `SET PERSIST max_connections=...` inserts a second, lowercase entry
instead of replacing the stale one.

## Expected result

Loading should canonicalize persisted variable names exactly like the write path
does, or the exact-match comparisons in `RESET PERSIST`/`SET PERSIST` should be
case-insensitive, so a legacy mixed-case entry can be found, updated and removed.