Skip to content

feat: an upgrade moves the database to MySQL 9.7 LTS safely - #25

Merged
blaipr merged 1 commit into
mainfrom
feat/mysql-9-7-migration
Nov 17, 2026
Merged

blaipr merged 1 commit into
mainfrom
feat/mysql-9-7-migration

Conversation

@blaipr

@blaipr blaipr commented Nov 17, 2026

Copy link
Copy Markdown
Member

What this changes

The docker setup now runs MySQL 9.7 LTS (ansibleforms/docker#50), and MySQL 9 removed the mysql_native_password plugin: a server whose my.cnf still sets mysql_native_password=ON refuses to start, and a user still on that plugin can no longer sign in. A compose upgrade replaced docker-compose.yml but kept the old data/mysql/my.cnf, so an upgraded install would not have come back up.

When the new compose file's mysqldb image is a higher MySQL line without the plugin (8.4.x to 9.7.x; a patch of the same line such as 8.4.11 to 8.4.13 or 9.7 to 9.7.5 is not), the upgrade now does this while the current MySQL still runs:

  1. Review (before the confirmation): asks the database which users are on mysql_native_password, through compose exec -T mysqldb as root with MYSQL_PWD, as the backup's dump does. The review says the database moves from MySQL 8.4.x to 9.7.x.
  2. Unknown users stop it: any user on the plugin other than root and the app's user (MYSQLDB_USER) stops the upgrade before anything changes. The message lists them with the ALTER USER command to run by hand. The users are asked again right before the backup.
  3. After the backup: root and the app's user move to caching_sha2_password with their passwords from the .env. The SQL goes on mysql's standard input, never on a command line, and passwords are scrubbed from any error.
  4. my.cnf: the mysql_native_password line goes from data/mysql/my.cnf (any case or spacing, _ or -). The other lines stay, and the old file is saved as my.cnf.<version>.bak.
  5. Then the normal upgrade goes on, and the 9.7 server upgrades the data directory on its first start.

Rollback: it puts my.cnf back. The moved users are harmless on 8.4, which has caching_sha2_password too. 8.4 cannot start on data that 9.7 already upgraded, so once the new containers were started, the rollback stops mysqldb and moves the data folder aside (data/mysql/db.<mysql version>.<time>). The old MySQL then starts on a new folder and the backup is loaded into it.

The Helm path (internal/kube) is untouched: the chart's my.cnf never set the line, and the chart handles its own MySQL.

What an operator sees

An upgrade with only root and the app's user on the plugin shows one more review paragraph and two more steps:

→ Moving the database users to caching_sha2_password: 'ansibleforms'@'%', 'root'@'%'
→ Removing mysql_native_password from data/mysql/my.cnf

When another user is on the plugin, the upgrade stops with nothing changed:

MySQL 9.7.4 no longer has mysql_native_password, and these database users still sign in with it: 'report'@'%'.
The installer only knows the passwords of root and the app's user. Move the others to caching_sha2_password with their own passwords, as root in the database:

  docker compose -p af exec mysqldb mysql -uroot -p
  ALTER USER 'report'@'%' IDENTIFIED WITH caching_sha2_password BY '<password>';

Then upgrade again. Nothing was changed.

Every new text is in all eleven languages.

Tests

The tests use table tests and a fake mysqlRun. They cover:

  • the version comparison;
  • the my.cnf edit and its restore;
  • parsing mysql's batch output (with its escapes);
  • SQL quoting;
  • the ALTER of the known users;
  • the stop on unknown users, checked against a snapshot showing every file unchanged and no statement run;
  • no query on a same-line upgrade.

I also checked the query, the batch escapes and the ALTER with an escaped password against a real mysql:8.4 container.

Checklist

  • Branch is named <type>/<description> and the title is a Conventional Commit
  • gofmt -l . prints nothing, and go vet ./... and go test ./... pass
  • Tried the changed flow with the built binary on a test machine, or the change does not affect it
  • New or changed texts are in every language under internal/i18n/locales

When the new compose file runs a MySQL line without mysql_native_password
(8.4.x to 9.7.x), the upgrade asks the running database which users still sign
in with it, moves root and the app's user to caching_sha2_password with their
passwords from the .env, and takes the mysql_native_password line out of
data/mysql/my.cnf. Any other user on it stops the upgrade before anything
changes, with the ALTER USER command to run by hand. A rollback puts my.cnf
back and, once the new MySQL started, moves its data aside so the old MySQL
starts on a new folder with the backup loaded.
@blaipr
blaipr merged commit db8e30b into main Nov 17, 2026
4 checks passed
@blaipr
blaipr deleted the feat/mysql-9-7-migration branch November 17, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant