Skip to content

feat(services): read MySQL and MariaDB settings from my.cnf in the data directory - #105

Merged
lukas-frey merged 2 commits into
flock-php:mainfrom
sloan58:feature/88-mysql-option-file
Nov 6, 2026
Merged

lukas-frey merged 2 commits into
flock-php:mainfrom
sloan58:feature/88-mysql-option-file

Conversation

@sloan58

@sloan58 sloan58 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #88

What

MySQL and MariaDB now start with --defaults-file=<data dir>/my.cnf instead of --no-defaults.

  • Flock creates my.cnf in the line's data directory (e.g. services/mysql/data/8.4/my.cnf) the first time it starts the server. It holds a commented [mysqld] template and is never overwritten, so edits survive restarts, flock services update and switching versions. Each version has its own data directory, so each has its own file, like postgresql.conf.
  • The file is written after initialising, because mysqld --initialize refuses a data directory that isn't empty. Existing installs get the file on their next start. With only comments in it, they behave exactly as before.
  • --defaults-file reads only that file, so Homebrew's /opt/homebrew/etc/my.cnf, /etc/my.cnf and ~/.my.cnf are still ignored.
  • Flock's own flags (--basedir, --datadir, --bind-address, --port, --socket, --mysqlx=OFF) come after it and win over the file.
  • MySQL now also loads SET PERSIST values from mysqld-auto.cnf, as documented. --no-defaults skipped that file too.
  • The --no-defaults used during initialisation and by the create-db client is unchanged.
  • Docs: a "MySQL and MariaDB settings" section in docs/services.md.

Testing

  • TestSQLSpecReadsTheDataDirectorysOptionFile: --defaults-file is the first argument, --no-defaults is gone, the file is created after initialising, and an edited file isn't overwritten on the next start.
  • gofmt, go vet and go test -race (excluding tools/, as in CI) pass on macOS.
  • End to end, with real servers: a throwaway test (not in this PR) took Flock's own packages from the manifest, checked their SHA-256, and ran them through Kind.Spec. Each run:
    1. initialises a fresh data directory, starts the server, and checks that my.cnf was written;
    2. edits it to ngram_token_size = 3 (MySQL) or innodb_ft_min_token_size = 2 (MariaDB), plus max_allowed_packet = 256M and port = 1234;
    3. restarts and checks that the settings apply, @@port is still Flock's port (the flag wins over the file's 1234), and the file wasn't overwritten;
    4. on MySQL, sets SET PERSIST sql_mode = ..., restarts again and checks it's still applied.
Platform MySQL 8.4.13 MariaDB 10.11.19 MariaDB 12.3.3
macOS 15, arm64 ✅ ✅ ✅
Ubuntu 24.04, x86_64 ✅ ✅ ✅
Windows 11 on ARM (x64 builds, emulated) ✅ ✅ ⚠️ see below

On Windows the run also used mysqladmin/mariadb-admin shutdown, and left no server running on any platform.

MariaDB 12.3.3 on Windows doesn't start with these arguments, and doesn't start with the current --no-defaults ones either, on a freshly initialised data directory. SSL setup fails: caching_sha2_password: failed to read private_key.pem then SSL error: Unable to get private key / Failed to setup SSL / Aborting. So it isn't caused by this change, and I'll open a separate issue for it. This change does give a workaround: with skip-ssl in my.cnf, it starts, answers queries (have_ssl = DISABLED) and shuts down cleanly. I've only seen it on Windows on ARM, so I can't say whether native x64 Windows is affected.

Also on Windows: mariadb-install-db.exe writes its own my.ini into the data directory. --defaults-file points at my.cnf, so that my.ini stays ignored, as it was under --no-defaults.

🤖 Generated with Claude Code

…ta directory

Start the server with --defaults-file=<data dir>/my.cnf instead of
--no-defaults. Flock creates the file the first time it starts the server
and never overwrites it, so a setting a project needs to match production
(sql_mode, max_allowed_packet, ngram_token_size, ...) survives restarts and
updates. Other my.cnf files on the machine are still ignored, Flock's own
flags still win over the file, and MySQL now loads SET PERSIST values from
mysqld-auto.cnf.

Fixes flock-php#88

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Persisted MySQL port settings can override Flock’s configured endpoint on restart, while the shared documentation example contains an unsupported variable that causes MariaDB startup to fail.

2 open issues
What changed in this PR

Adds per-data-directory MySQL and MariaDB configuration, addressing #88 so local services can use application-specific server settings.

Changes:

  • Starts servers with --defaults-file and creates a template after initialization without overwriting existing edits.
  • Adds a regression test for argument ordering, file creation timing, and preservation of edits.
  • Documents configuration locations, example settings, and restart behavior.
File Description
internal/​catalog/​kinds.go Creates my.cnf when absent and uses it for server startup.
internal/​catalog/​catalog_test.go Tests option-file creation, startup arguments, and preservation.
docs/​services.md Explains custom MySQL and MariaDB settings.

Review effort: Balanced

Comment thread internal/catalog/kinds.go Resolved
Comment thread docs/services.md Resolved

@onairmarc onairmarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please address copilot findings

…cs example

MySQL loads mysqld-auto.cnf after the command line, so a port, bind address,
socket or directory written into it by hand would win over Flock's flags on
the next start. MySQL itself refuses to SET PERSIST these, so only a hand
edit can do it: Flock now doesn't start the server then, and names the file
and the setting to remove. Other persisted settings keep working.

The docs' example used ngram_token_size, which MariaDB doesn't know and
won't start with. The shared example now uses settings both servers have,
and the n-gram one is marked MySQL only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@onairmarc
onairmarc enabled auto-merge November 4, 2026 19:02
@onairmarc
onairmarc requested a review from lukas-frey November 4, 2026 19:02
@lukas-frey

Copy link
Copy Markdown
Member

Hi @sloan58 thanks for this PR! Merging it

@lukas-frey
lukas-frey disabled auto-merge November 6, 2026 20:20
@lukas-frey
lukas-frey merged commit e063ff0 into flock-php:main Nov 6, 2026
17 checks passed
@onairmarc onairmarc modified the milestone: v1.1.0 Nov 7, 2026
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.

Feature request: custom server settings for MySQL and MariaDB (a my.cnf instead of --no-defaults)

4 participants