Skip to main content

Module mysql

Module mysql 

Source
Expand description

A single-node MySQL container. Defaults to a test/test/test user/password/database trio (plus MYSQL_ROOT_PASSWORD=test) so MySqlGuard::connection_string is usable with zero configuration; call MySqlContainer::with_username/MySqlContainer::with_password/ MySqlContainer::with_database before start() to override any of them.

§Readiness — empirically pinned, not guessed

The official entrypoint boots mysqld twice: once as a throwaway “temp server” to run init scripts, then for real. Both prints, plus the X Plugin’s own “ready for connections” line, contain the substring ready for connections, and naively counting occurrences is a trap: the temp server’s X Plugin binds port: 33060 — whose digits start with 3306, so an unanchored port: 3306 search false-matches it too. Captured verbatim from a real docker run mysql:8.4 boot with this module’s env (MYSQL_USER=test, MYSQL_DATABASE=test, MYSQL_ROOT_PASSWORD=test):

[System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
[System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.4.10'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
...(init scripts run, temp server shuts down)...
[System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.4.10'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

Four lines contain ready for connections; only the last is the real server bound to 3306. The temp server prints port: 0 (no port yet) and the X Plugin lines print 33060, whose 3306 prefix would satisfy an unanchored match — so simple occurrence-counting is fragile here. The fix is a regex anchored on the real server’s port: 3306 with a trailing non-digit-or-end boundary (.*mysqld: ready for connections.*port: 3306($|[^0-9]).*). This module implements that same anchoring logic as a small custom WaitStrategy with hand-written character-boundary checks rather than a regex — predates Wait::for_log_message’s move to a real regex engine (regex-lite), and the hand-written version is unaffected by that swap since it was never routed through the shared matcher.

Structs§

MySqlContainer
A single-node MySQL container.
MySqlGuard
The running guard for a MySqlContainer.