MySQL 8.4: an owned server with separate migrator and runtime access

Start Oracle MySQL with private initialization, then check PDO, utf8mb4 and the boundary between migrations and application runtime access.

A stack of green discs, a mechanical holder and cards with a pen.

Having the pdo_mysql PHP module does not yet give an application a database. In the next manual step we started Oracle MySQL 8.4.13 in the same disposable Debian VM and tested two separate users through real PDO connections. This is a teaching schema, article_demo; Article itself, its Composer installation and migrations were not delivered to this fixture.

Minimal server core and one initialization

We used the server core with a custom configuration and systemd unit. A separate nonlogin user, s200-mysql, owns the data directory and log; root owns the configuration. Initial startup was prepared without TCP: skip-networking=ON and a private Unix socket in a 0700 runtime directory. mysqld --defaults-file=/etc/solution200-mysql.cnf --initialize-insecure --user=s200-mysql ran once.

After initialization the first start stopped: the compiled secure-file-priv default referred to a missing mysql-files directory. The data directory already contained initialized data. We read the cause and changed the policy to secure-file-priv=NULL, disabling server-side file import/export. Initialization was not repeated; this corrected the startup configuration.

We secured root and created two application users through the private socket. Passwords were generated inside the VM, remained in root-only 0600 files and reached the client through private stdin or an option file. Once the root password was set, an empty password was rejected.

Local TCP for the application

After securing bootstrap, we separately switched the server to loopback TCP. This is a shortened excerpt of the actual configuration; it omits other resource and filesystem settings:

[mysqld]
datadir=/var/lib/solution200-mysql
socket=/run/solution200-mysql/mysql.sock
skip-networking=OFF
bind-address=127.0.0.1
mysqlx=OFF
skip-name-resolve=ON
character-set-server=utf8mb4
collation-server=utf8mb4_0900_as_ci
secure-file-priv=NULL

The listener table contained only 127.0.0.1:3306 for MySQL; port 33060 was not listening. The private socket remained available to the administrator. This transition admitted local PDO, not the public network. The service used its own data/log directories, no capabilities, ProtectSystem=strict and MemoryMax=384M. That limit belongs to this test profile, not a production recommendation.

Regular queries and migrations have different privileges

article_runtime received only data reading and modification privileges. article_migrator additionally received DDL inside article_demo. Both identities are bound to 127.0.0.1. These grants follow separate user creation with private passwords:

SELECT @@GLOBAL.partial_revokes;

On this test server, the query returned 0 (OFF). In this mode, an unescaped _ in a database-level GRANT is a wildcard: the original article_demo grant also let both users access the control schema articleXdemo. We granted the literal article\_demo scope and revoked the old wildcard grants; the corrected setup is shown below. See MySQL GRANT.

CREATE DATABASE article_demo
    CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci;
GRANT SELECT, INSERT, UPDATE, DELETE
    ON `article\_demo`.* TO 'article_runtime'@'127.0.0.1';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX, REFERENCES
    ON `article\_demo`.* TO 'article_migrator'@'127.0.0.1';

The grants contain no global privileges or GRANT OPTION. Runtime must not modify the schema during a regular HTTP request. The migrator can create, alter and drop tables in this database. A database-level DROP privilege also allows the database itself to be dropped. Creating neighbouring databases and delegating privileges remain forbidden.

After the correction, fresh PDO connections for both users received 1044 for USE articleXdemo. Runtime DML and the migrator’s table DDL in article_demo still worked; runtime DROP TABLE received 1142. Only the separately owned control schema was created and removed; article_demo and its persisted emoji marker were retained. The database-level DROP capability is documented by MySQL DROP DATABASE.

PDO tests access and denial

We opened a real connection for each identity. This shows the call structure: user and password came from a private runtime source, not command-line arguments:

$db = new PDO(
    'mysql:host=127.0.0.1;port=3306;dbname=article_demo;charset=utf8mb4',
    $user,
    $password,
    [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);

The migrator created and altered a control table. Runtime performed INSERT, SELECT, UPDATE and DELETE. Its CREATE, ALTER and DROP attempts received 1142; GRANT received 1044; reading mysql.user received 1142. The migrator received 1044 for CREATE DATABASE outside its schema. A deliberately wrong password was rejected. Afterwards the migrator dropped its control table.

We separately read the schema collation: utf8mb4_0900_as_ci. Writing and reading the emoji 😀 preserved its four-byte value. Case compared equal to case, while e did not equal é: this collation is case-insensitive and accent-sensitive. The exercise therefore checked both stored data and comparison behaviour.

Readiness means a successful authenticated query

We added a root-only helper to the custom unit’s ExecStartPost. It invokes the client using a private option file:

mysql --defaults-file=/root/solution200-data-secrets/mysql-admin.cnf \
    --batch --skip-column-names

The helper sends SELECT 1 through stdin and requires the exact response 1. While the socket is not ready, it admits only connection error 2002 and checks that the main process is alive. An authentication error or another unexpected cause stops the check; there is no automatic restart. A process or an open 3306 port does not replace an authenticated query.

In this exercise MySQL ran locally, PDO verified privileges, and startup remained disabled. At this initial stage, reboot had not yet been checked. This foundation is not evidence that Article itself is ready or that CLI automation is complete.

Later, we explicitly enabled the custom service and performed an ordinary joint reboot of the fixture. Startup completed an authenticated SELECT 1; PDO read the persisted emoji marker in boot_probe, while runtime DDL again received 1142. This confirms the local scenario, not application or CLI readiness.

Repeated the same access boundaries through the CLI

In a separate clean CLI run, MySQL completed installation, configuration, initialization, root protection and independent startup verification. Then site-plan, site-apply and site-verify created a new article_demo, two accounts and another new control database with a similar name. The CLI confirmed owned CREATE/ALTER/DROP, INSERT and SELECT and rejected app DDL, app writes outside the namespace and migrator DDL outside the namespace.

The executed independent verification below uses generalized protected paths. site.json contains schema_version: 1 and namespace: article_demo; dependencies refer to the original completed foundation/packages/configuration/activation. The key SHA and approved-plan SHA have already been checked.

deploy-cli host data mysql84 site-verify \
  --env-file "$PRIVATE_DIR/administrator.env" \
  --request-file "$PRIVATE_DIR/request.json" \
  --data-file "$PRIVATE_DIR/mysql84-profile.json" \
  --site-file "$PRIVATE_DIR/site.json" \
  --key-file "$PRIVATE_DIR/mysql84.gpg" \
  --key-sha256 "$MYSQL_PUBLIC_KEY_SHA256" \
  --dependencies-file "$PRIVATE_DIR/mysql84-site-deps.json" \
  --plan-file "$PRIVATE_DIR/mysql84-site-plan.json" \
  --plan-sha256 "$APPROVED_PLAN_SHA256"

This summarizes the completed journal: grant_rows counts SHOW GRANTS rows; the remaining fields come from control reads. Actual partial_revokes was OFF, so the database grant target escaped the underscore. Passwords remained in root-only files inside the demonstration VM.

{
  "phase": "committed",
  "grant_rows": {
    "app": 2,
    "ddl": 2
  },
  "outside_control": "ok",
  "outside_read_denied": true,
  "own_read": true,
  "partial_revokes": false
}
Fresh reduced recheck after the joint reboot: PDO reads the persisted emoji marker while the system schema remains inaccessible to the runtime user.
Fresh reduced readback after the grant correction: the intended schema is accessible and the similar name is denied for both roles.

A separate CLI step for starting and enabling the existing service

After rebooting the combined CLI fixture, this service was stopped and disabled. We did not replay its original activation: for MySQL that sequence also initializes the data directory and secures root. The new startup transaction uses existing data and checks the original completed journals, all nine package-history nodes, unchanged configuration and independently confirmed current boot.

Before starting, the CLI compares exact configuration and private-file images, including Elasticsearch TLS material. A new drop-in adds Requires and After dependencies on the owned firewall. The CLI starts the service once, verifies its actual process, signed binary, loopback listeners and authenticated native protocol, then creates the exact enable link after readiness succeeds.

The commands below use generalized private paths. PRIVATE_DIR is an absolute private directory; install-request retains the installation boot, while current-console-request independently confirms the current boot. The public PHP key admits the original combined history; data-service keys are retained in history-references. The plan SHA is checked before apply.

STARTUP_ARGS=(
  --env-file "$PRIVATE_DIR/administrator.env"
  --request-file "$PRIVATE_DIR/install-request.json"
  --fpm-file "$PRIVATE_DIR/php-profile.json"
  --key-file "$PRIVATE_DIR/php-archive-keyring.gpg"
  --key-sha256 "$PHP_PUBLIC_KEY_SHA256"
  --references-file "$PRIVATE_DIR/history-references.json"
  --current-request-file "$PRIVATE_DIR/current-console-request.json"
  --data-activations-file "$PRIVATE_DIR/data-activations.json"
  --firewall-pin-file "$PRIVATE_DIR/firewall-pin.json"
)

deploy-cli host runtime-startup mysql84 plan \
  "${STARTUP_ARGS[@]}" --plan-file "$PRIVATE_DIR/mysql84-startup-plan.json"

deploy-cli host runtime-startup mysql84 apply \
  "${STARTUP_ARGS[@]}" --plan-file "$PRIVATE_DIR/mysql84-startup-plan.json" \
  --plan-sha256 "$APPROVED_STARTUP_PLAN_SHA256" --approve-privileges

This is a reduced summary of the actual journal and independent verification over a new SSH connection, rather than the literal output of one command:

{
  "unit": "deploy-cli-mysql84.service",
  "state": "active/running",
  "startup": "enabled",
  "journal_steps": 8,
  "protocol": {
    "collation": "utf8mb4_0900_as_ci",
    "empty_root_denied": true,
    "mysqlx_disabled": true,
    "partial_revokes": false,
    "secure_file_priv": "NULL",
    "skip_networking": false,
    "version": "8.4.13"
  }
}

An action recorded as pending is never dispatched again on a subsequent invocation. A completed journal is verified through reads only. Original configuration, credentials, package state and previous journals remained unchanged after this step. This was the separate start/enable stage; acceptance of the combined reboot follows below.

Access controls and data after the combined reboot

After separate start/enable, we performed an ordinary reboot of the local educational VM together with PHP-FPM, Nginx and timers. An independent serial console confirmed the new boot. The CLI checked the original journal and configuration, then rebuilt current processes, listeners and protocol replies. The original STARTUP_ARGS are retained; the new console request is passed separately.

deploy-cli host runtime-startup mysql84 boot-verify "${STARTUP_ARGS[@]}" \
  --plan-file "$PRIVATE_DIR/mysql84-startup-plan.json" \
  --plan-sha256 "$APPROVED_STARTUP_PLAN_SHA256" \
  --manifest-sha256 "$COMMITTED_STARTUP_MANIFEST_SHA256" \
  --new-boot-request-file "$PRIVATE_DIR/new-boot-console-request.json" \
  --output-file "$PRIVATE_DIR/mysql84-new-boot-proof.json"

MySQL returned automatically as active/running and enabled. Collation remained utf8mb4_0900_as_ci and partial_revokes remained OFF. Control data in both the allowed and unrelated databases were retained; unrelated database reads were denied for app and ddl. Server initialization and grants were not replayed.

The frame below belongs to the earlier start/enable stage before the combined reboot. The new post-reboot result is described above; the two stages remain distinct.

Data-service startup before the combined reboot. Service state and sysctl were read live; explicitly reduced retained access-control results follow.
  1. Data & Infrastructure How to share VPS resources between several products
  2. Databases Four database access roles for one product
  3. Architecture Debian service users: a separate identity for each application
  4. Operations & Security Startup and reboot: firewall, ready FPM, then Nginx
  5. Operations & Security Two PHP-FPM pools: separate UIDs, Unix sockets and file rights
  6. Data & Infrastructure Redis: private access, ACLs and checking keys outside the allowed namespace