Skip to content

Keep the grant option when editing privileges on MySQL 8.0.11+ - #20523

Open
cB-Abhinav-Gautam wants to merge 1 commit into
phpmyadmin:masterfrom
cB-Abhinav-Gautam:fix-grant-option-mysql8
Open

cB-Abhinav-Gautam wants to merge 1 commit into
phpmyadmin:masterfrom
cB-Abhinav-Gautam:fix-grant-option-mysql8

Conversation

@cB-Abhinav-Gautam

@cB-Abhinav-Gautam cB-Abhinav-Gautam commented Oct 11, 2026 •

Copy link
Copy Markdown

Description

Since MySQL 8.0.11, generateQueriesForUpdatePrivileges() moves the WITH clause from the GRANT statement to ALTER USER. getWithClauseForAddUserAndUpdatePrivs() correctly leaves GRANT OPTION out of that clause, because ALTER USER cannot set it. However, nothing put it back on the GRANT. As a result, ticking "Grant" when editing global, database, table or routine privileges silently dropped the grant option.

This change appends WITH GRANT OPTION to the GRANT statement in that case, as the add-user path already does. The ALTER USER statement and the queries for MySQL < 8.0.11 and MariaDB are unchanged.

Before (MySQL 8.4, database level, Grant ticked):

GRANT SELECT ON `db`.* TO 'u'@'h';
ALTER USER 'u'@'h' ;

After:

GRANT SELECT ON `db`.* TO 'u'@'h' WITH GRANT OPTION;
ALTER USER 'u'@'h' ;

Tests

  • testUpdatePrivilegesAfterMySql8Dot11 now expects the grant option. It posts Grant_priv=Y and previously asserted the buggy output.
  • New test testGenerateQueriesForUpdatePrivilegesKeepsGrantOptionAfterMySql8Dot11 covers the database-level case from does not set a GRANT at the database level for a database user #19605.
  • Checked on a real MySQL 8.4: with the new statements, SHOW GRANTS reports ... WITH GRANT OPTION.

Refs #19605 and the new issue #20521

The same fix is also opened against QA_5_2.

Since MySQL 8.0.11, generateQueriesForUpdatePrivileges() moves the WITH
clause from the GRANT statement to ALTER USER, and
getWithClauseForAddUserAndUpdatePrivs() correctly leaves GRANT OPTION out
of it because ALTER USER cannot set it. Nothing put it back on the GRANT,
so ticking "Grant" when editing global, database, table or routine
privileges silently dropped the grant option. Append WITH GRANT OPTION to
the GRANT statement in that case, as the add-user path already does.

Refs phpmyadmin#19605

Signed-off-by: Abhinav Gautam <abhinav@codebuckets.in>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YE52bG3MYFauvkA4kmDur
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.

1 participant