TRUNCATE Privilege
This page is part of MariaDB's Documentation.
The parent of this page is: Privileges for MariaDB Xpand
Topics on this page:
Overview
Grants the ability to execute TRUNCATE
.
DETAILS
Scope: Global, Database, Table
Privilege name for
GRANT
:TRUNCATE
Privilege name for
REVOKE
:TRUNCATE
Privilege shown by
SHOW GRANTS
:TRUNCATE
EXAMPLES
GRANT
The following examples demonstrate grant of a single privilege. A single GRANT
statement can grant multiple privileges at the same scope by providing a comma-separated list of the privileges.
To grant the TRUNCATE
privilege at global scope, replace the user specification ('USERNAME'@'HOSTNAME'
) in the following query to align to your requirements:
GRANT TRUNCATE
ON *.*
TO 'USERNAME'@'HOSTNAME';
To grant the TRUNCATE
privilege at database scope, replace the user specification ('USERNAME'@'HOSTNAME'
) and database name (DATABASE_NAME
) in the following query to align to your requirements:
GRANT TRUNCATE
ON DATABASE_NAME.*
TO 'USERNAME'@'HOSTNAME';
To grant the TRUNCATE
privilege at table scope, replace the user specification ('USERNAME'@'HOSTNAME'
), database name (DATABASE_NAME
), and table name (TABLE_NAME
) in the following query to align to your requirements:
GRANT TRUNCATE
ON DATABASE_NAME.TABLE_NAME
TO 'USERNAME'@'HOSTNAME';
REVOKE
The following examples demonstrate revoke of a single previously-granted privilege. A single REVOKE
statement can revoke multiple privileges at the same scope by providing a comma-separated list of the privileges.
To revoke the TRUNCATE
privilege at global scope, replace the user specification ('USERNAME'@'HOSTNAME'
) in the following query to align to your requirements:
REVOKE TRUNCATE
ON *.*
FROM 'USERNAME'@'HOSTNAME';
To revoke the TRUNCATE
privilege at database scope, replace the user specification ('USERNAME'@'HOSTNAME'
) and database name (DATABASE_NAME
) in the following query to align to your requirements:
REVOKE TRUNCATE
ON DATABASE_NAME.*
FROM 'USERNAME'@'HOSTNAME';
To revoke the TRUNCATE
privilege at table scope, replace the user specification ('USERNAME'@'HOSTNAME'
), database name (DATABASE_NAME
), and table name (TABLE_NAME
) in the following query to align to your requirements:
REVOKE TRUNCATE
ON DATABASE_NAME.TABLE_NAME
FROM 'USERNAME'@'HOSTNAME';
SHOW Output
A user's privileges can be displayed using the SHOW GRANTS
statement.
If the TRUNCATE
privilege is present, it will be shown as TRUNCATE
in the output. For example:
SHOW GRANTS FOR 'app_user'@'192.0.2.%';
+--------------------------------------------------------+
| Grants for app_user@192.0.2.% |
+--------------------------------------------------------+
| GRANT TRUNCATE ON `app_db`.* TO 'app_user'@'192.0.2.%' |
+--------------------------------------------------------+
Privilege Failure
TRUNCATE TABLE
requires either the DROP
privilege or the TRUNCATE
privilege. An error message is raised if an operation fails due to insufficient privileges. For example:
TRUNCATE TABLE hq_sales.invoices;
ERROR 1045 (HY000): [11281] Permission denied: User 'USERNAME'@'HOSTNAME` is missing DROP on `db1`.`customers`; transaction aborted