h3. CIDR notation for account host names (
MDEV-25515)
An IPv4 account host can now be specified using a CIDR prefix, for example {{CREATE USER u@'192.168.0.0/24'}}. This is equivalent to {{'192.168.0.0/255.255.255.0'}}.
The prefix is converted to the netmask form when the statement is parsed. Therefore, the netmask form is stored and displayed by {{SHOW GRANTS}}.
h4. Removing an old literal CIDR account requires a direct DELETE
Earlier versions accepted a host such as {{10.0.0.0/24}} and stored it as plain text. Such an account never matched any client and therefore never worked.
The server now converts {{10.0.0.0/24}} to {{10.0.0.0/255.255.255.0}} before looking up the account. As a result, {{DROP USER}} and {{RENAME USER}} can no longer find the old row, and {{DROP USER u@'10.0.0.0/24'}} fails.
Such a row is skipped when privileges are loaded, and a warning is written to the error log. Consequently, the account grants no access.
To remove the old account, delete its row from the privilege tables and reload the privileges:
{code:sql}
DELETE FROM mysql.global_priv WHERE User='u' AND Host='10.0.0.0/24';
-- Repeat for mysql.db, mysql.tables_priv, mysql.columns_priv,
-- mysql.procs_priv, mysql.proxies_priv, and mysql.roles_mapping
-- if they contain rows for this account.
FLUSH PRIVILEGES;
{code}
h4. Compatibility with MySQL 8.0
MySQL 8.0.23 also introduced CIDR notation for account host names, but handles it differently.
|| Behavior || MySQL 8.0 || MariaDB ||
| Storage | Stored exactly as specified ({{/24}} remains {{/24}}) | Converted to the netmask form |
| {{/24}} and {{/255.255.255.0}} for the same user | Stored as separate accounts; one can shadow the other | Converted to the same netmask form; duplicate accounts are rejected |
| Invalid hosts (see below) | Accepted and stored, but never match any client | Rejected with {{ER_INVALID_HOST_NETMASK}} when created or renamed to |
| Existing invalid hosts or literal-CIDR rows | Not applicable | Skipped when privileges are loaded, with a warning in the error log |
Invalid hosts include host bits being set ({{10.0.3.5/24}}), {{/0}}, a prefix greater than 32, a non-contiguous netmask, and a wildcard combined with a prefix.
When migrating from MySQL:
* Account statements from a MySQL 8.0 dump, such as {{CREATE USER}} and {{GRANT}}, work because MariaDB converts CIDR prefixes to the netmask form. Statements specifying invalid hosts listed above fail. MySQL never matched such accounts either.
* A raw privilege-table row containing a literal CIDR host, for example from a restored dump of the {{mysql}} schema, is not converted by the server. The account is skipped when privileges are loaded and cannot be used to log in until the row is rewritten in netmask form, for example {{10.0.0.0/255.255.255.0}}.
* MySQL 8.0 system tables cannot be reused in place. Converting such rows is the responsibility of migration tooling, not the server.