← All updates

Engineering / Field note

One underscore can widen a MySQL database grant

MySQL’s database-grant patterns need a separate review from identifier quoting, explicit privileges and the partial_revokes setting. Five fictional examples show why.

By Zyel · Published · 4 min read

A database name can look exact while a grant treats part of it as a pattern. MySQL 8.4 permits underscore and percent wildcards in database-level grants. In wildcard mode, an underscore can match a character in another database name. That makes a familiar-looking name such as reports_archive a poor basis for a simple string-equality security check. [1] [2]

This reference note was reviewed on November 30, 2026 against the MySQL 8.4 manual. The documented behavior is established, and database-grant wildcards are deprecated. The five fictional JSON records below use our own review format to make the reasoning visible. They describe expected review decisions, with no claim of an executed grant or a particular server’s condition. [1]

First establish how the name will be interpreted

The same text needs different treatment depending on partial_revokes. MySQL documents that enabling this setting makes unescaped underscore and percent characters in schema privilege assignments literal. A reviewer therefore needs the actual setting, alongside the server version and grant level. An omitted value leaves the interpretation unresolved. [3]

Example 1 — Defer a name check when its interpretation is unknown · JSON
{
  "fixture": "interpretation_missing",
  "mysql_manual_series": "8.4",
  "grant_level": "database",
  "identifier_quoted": true,
  "database_name_in_grant": "reports_archive",
  "partial_revokes": null,
  "direct_privileges": [
    "SELECT"
  ],
  "intended_schema": "reports_archive",
  "allowed_privileges": [
    "SELECT"
  ],
  "other_privilege_paths": "not_assessed",
  "expected_review": "defer_interpretation"
}

The null value is intentional. It prevents an evidence collector from silently substituting its own environment’s setting for the environment being reviewed. Our fictional policy allows only SELECT for one reporting schema. The other_privilege_paths field keeps the limited direct-grant assessment separate from a complete account review.

Identifier quoting does not settle wildcard scope

The GRANT manual gives an escaped, quoted database-name example for a literal underscore. Backticks handle identifier quoting; they do not by themselves neutralize an underscore’s wildcard meaning in a database-level pattern. The second record deliberately sets identifier_quoted to true while leaving the underscore unescaped. [1]

Example 2 — Reject a quoted name that still carries a wildcard · JSON
{
  "fixture": "quoted_name_still_patterns",
  "mysql_manual_series": "8.4",
  "grant_level": "database",
  "identifier_quoted": true,
  "database_name_in_grant": "reports_archive",
  "partial_revokes": false,
  "direct_privileges": [
    "SELECT"
  ],
  "intended_schema": "reports_archive",
  "allowed_privileges": [
    "SELECT"
  ],
  "other_privilege_paths": "not_assessed",
  "matching_name_examples": [
    "reports_archive",
    "reportsXarchive"
  ],
  "expected_review": "reject_pattern_scope"
}

Here, reportsXarchive illustrates the extra match: X occupies the position of the underscore. Percent permits a sequence of characters, including an empty sequence. These are pattern examples, not a discovery of additional databases. A matching-looking label is useful for a human; an authorization review has to inspect what the label means. [2]

Preserve the distinction between a literal and its encoding

For database-level grants using wildcard interpretation, the documented escape for a literal underscore is a backslash before it. The next record represents that token in JSON. JSON displays two backslashes to encode one backslash in the decoded value. Review the decoded token and its destination syntax rather than counting slashes in a screenshot. [1]

Example 3 — Record an escaped literal scope and a narrow privilege set · JSON
{
  "fixture": "escaped_literal_name",
  "mysql_manual_series": "8.4",
  "grant_level": "database",
  "identifier_quoted": true,
  "database_name_in_grant": "reports\\_archive",
  "partial_revokes": false,
  "direct_privileges": [
    "SELECT"
  ],
  "intended_schema": "reports_archive",
  "allowed_privileges": [
    "SELECT"
  ],
  "other_privilege_paths": "not_assessed",
  "expected_review": "matches_direct_projection"
}

The expected result is deliberately named matches_direct_projection. It means this fictional name and explicit privilege list fit their stated target. It does not establish which account a connection used, what another grant permits, or whether a role supplies additional access. A precise result is more useful than a broadly optimistic green tick.

Treat a setting change as a change in meaning

With partial_revokes enabled, MySQL treats the unescaped characters literally. That changes the interpretation of the raw name in the fourth record. It also explains why moving a grant reviewer between environments requires more than copying its string comparisons. [3]

Example 4 — Bind the literal interpretation to the relevant setting · JSON
{
  "fixture": "partial_revokes_literal_mode",
  "mysql_manual_series": "8.4",
  "grant_level": "database",
  "identifier_quoted": true,
  "database_name_in_grant": "reports_archive",
  "partial_revokes": true,
  "direct_privileges": [
    "SELECT"
  ],
  "intended_schema": "reports_archive",
  "allowed_privileges": [
    "SELECT"
  ],
  "other_privilege_paths": "not_assessed",
  "expected_review": "matches_direct_projection"
}

Enabling the setting supports partial revocation of global privileges for particular schemas. It is an access-control setting with consequences beyond one database name. Our practical recommendation is to review existing privilege assignments and their intended interpretation before changing it. Keep the documented version context with the review; deprecation makes assumptions about future releases especially unhelpful. [3]

Check the privileges as well as the destination

A literal schema boundary can still contain more authority than an application needs. MySQL distinguishes operations through privileges such as SELECT and INSERT, while ALL is a shorthand for the privileges available at the applicable level. In our fictional reporting policy, adding INSERT exceeds the stated SELECT-only requirement even when the schema name is exact. [5]

Example 5 — Reject excess rights inside the intended literal schema · JSON
{
  "fixture": "literal_scope_excess_rights",
  "mysql_manual_series": "8.4",
  "grant_level": "database",
  "identifier_quoted": true,
  "database_name_in_grant": "reports\\_archive",
  "partial_revokes": false,
  "direct_privileges": [
    "SELECT",
    "INSERT"
  ],
  "intended_schema": "reports_archive",
  "allowed_privileges": [
    "SELECT"
  ],
  "other_privilege_paths": "not_assessed",
  "expected_review": "reject_privilege_set"
}

For an actual account review, MySQL’s SHOW GRANTS documents both privilege and role assignments. Its USING clause can expose privileges associated with named granted roles. Review that context, relevant global grants and delegation separately before describing an account’s effective access. A single tidy database-level line answers a smaller question. [4]

The operational payoff is a clearer review sequence: establish the version and interpretation setting, read the exact scope token, check the explicit privilege set, and collect the remaining account context. Those steps turn a name that merely looks right into a conclusion whose boundaries another person can inspect.

Sources + further reading

Source dates describe the original material. Publication above is the date this Zyel article went live.

  1. MySQL 8.4 GRANT statementOracle / MySQL · Checked Nov 30, 2026
  2. MySQL 8.4 pattern matchingOracle / MySQL · Checked Nov 30, 2026
  3. MySQL 8.4 partial revokesOracle / MySQL · Checked Nov 30, 2026
  4. MySQL 8.4 SHOW GRANTSOracle / MySQL · Checked Nov 30, 2026
  5. MySQL 8.4 privilegesOracle / MySQL · Checked Nov 30, 2026

Reader discussion

What would you ask next?

Questions, useful corrections and thoughtful disagreement are welcome. Comments are reviewed before they appear.

No reader comments yet.

10–2,000 characters. Plain text. Leave out passwords, private project data and personal contact details. A blank display name appears as Anonymous.

Complete the CAPTCHA before sending. Verification runs on your device.