Skip to content

Fix hardcoded GRANT username in db/data.sql - #147

Closed
buzz-code wants to merge 1 commit into
mainfrom
claude/fix-data-sql-hardcoded-mysql-user
Closed

buzz-code wants to merge 1 commit into
mainfrom
claude/fix-data-sql-hardcoded-mysql-user

Conversation

@buzz-code

Copy link
Copy Markdown
Owner

What

Removes a redundant, hardcoded GRANT SYSTEM_USER ON *.* TO 'mysql_user'@'%'; FLUSH PRIVILEGES; from db/data.sql.

Why

Ran into this deploying a fresh instance (Dokploy, db/Dockerfile building the seeded MySQL image): with MYSQL_USER set to anything other than the literal string mysql_user, the database container's init step failed outright:

ERROR 1410 (42000) at line 9: You are not allowed to create a user with GRANT

MySQL 8.4 no longer allows a bare GRANT to implicitly create a nonexistent user. Since the official MySQL entrypoint auto-creates the MYSQL_USER account before running /docker-entrypoint-initdb.d/ scripts, this only ever worked when MYSQL_USER=mysql_user exactly — any other username broke the whole seed script (schema + migrations table population), leaving a completely empty database. From there, typeorm:run tries to replay full migration history from scratch, and the very first migration (KlassAddReferenceId1675356165986) crashes because it assumes a klasses table that only ever existed via this checkpoint or historical synchronize.

db/init-grants.sh already performs this exact grant correctly, using ${MYSQL_USER} dynamically. The line in data.sql was dead weight and the actual point of failure.

Verification

Rebuilt the db image with a non-default MYSQL_USER/MYSQL_DATABASE/MYSQL_PASSWORD against this fix — init completes cleanly, migrations table is seeded as expected, and the server boots and passes its healthcheck against the resulting database.

Scope note: this only fixes the specific breakage above. It doesn't change anything about how a truly empty database (skipping db/data.sql entirely) would still need to replay all 164 migrations from a synchronize-era baseline that doesn't exist in migration history — that's a separate, bigger discussion if it's worth solving generally.


Generated by Claude Code

The GRANT SYSTEM_USER statement hardcoded 'mysql_user' as the
username, breaking any fresh install that uses a different
MYSQL_USER value (fails with 'You are not allowed to create a
user with GRANT' on MySQL 8.4 since that literal user doesn't
exist).

db/init-grants.sh already does this exact grant correctly and
dynamically via ${MYSQL_USER}, so the line in data.sql was both
redundant and the actual cause of the bug. Removing it lets a
fresh install use any DB username.
Copilot AI lite review requested due to automatic review settings August 21, 2026 08:53

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.

Pull request overview

Fix MySQL seed init failure on fresh deploy when MYSQL_USER != mysql_user, by removing dead, hardcoded GRANT ... TO 'mysql_user'@'%' from db/data.sql (dynamic grant already in db/init-grants.sh).

Changes:

  • Delete hardcoded GRANT SYSTEM_USER ... TO 'mysql_user'@'%' + FLUSH PRIVILEGES from db/data.sql
  • Keep privilege grant path via db/init-grants.sh using ${MYSQL_USER}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@buzz-code

Copy link
Copy Markdown
Owner Author

נסגר ככפילות: השינוי ב-data.sql כלול ב-#148 (יחד עם docker-compose ל-MySQL משותף).

@buzz-code buzz-code closed this Sep 22, 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.

3 participants