Solution

Why MySQL 5.7 keeps old credentials after container replacement

The helper reuses /data/mysql5.7/data when replacing mysql57. MySQL initializes accounts only for an empty data directory, so changing install variables does not reset an existing database.

Updated 2026-10-29

Problem statement

I supplied a new MYSQL_ROOT_PASSWORD, database, or user on a rerun. Why are the old credentials and data still there?

The helper removes and recreates a same-name container, but mounts the existing host directory /data/mysql5.7/data into it. Removing a container does not remove this bind-mounted database.

The official MySQL image applies MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD and initialization files when creating a database in an empty data directory. With an existing database, these settings do not rewrite accounts or data. A newly generated password printed by the helper can therefore differ from the password accepted by the reused database.

Do not delete or empty the data directory to force initialization. First identify the active mount and preserve the database. If an authorized account still works, change credentials through a reviewed SQL/admin procedure; if access is lost, plan and verify backup and recovery before any mutation.

What to check

  • Read-only: docker inspect mysql57 --format "{{json .Mounts}}" identifies the actual data mount.
  • Read-only: docker ps --filter name=mysql57 and docker logs --tail 100 mysql57 show state/startup output; logs may contain sensitive data.
  • If an authorized account still works, run SELECT VERSION(), CURRENT_USER(); to confirm the actual server and account.
  • Keep the original data directory until a tested backup and recovery plan exists. Container recreation is not a database reset.

Parent topic

Use PHP 7.2 and Workerman 3.5.24 examples for inherited compatibility work with an upgrade plan.