gcloud sql users assign-roles grants or revokes database roles
Introduced 2026-02-03 · score 0.98
HOW TO USE IT
For a Cloud SQL MySQL or PostgreSQL user, use `gcloud sql users assign-roles` to grant roles; add `--revoke-existing-roles` to replace existing roles, or pass an empty `--database-roles` value with it to revoke all roles.
gcloud sql users assign-roles <USERNAME> --instance=<INSTANCE> --database-roles=<ROLE_1>,<ROLE_2> --type=BUILT_INgcloud sql users assign-roles <USERNAME> --instance=<INSTANCE> --revoke-existing-roles --database-roles=<ROLE_1>,<ROLE_2> --type=BUILT_INgcloud sql users assign-roles <USERNAME> --type=BUILT_IN --instance=<INSTANCE> --database-roles= --revoke-existing-rolesWHY THIS HELPS
Grant or revoke roles for a Postgres or MySQL user in Cloud SQL.
REQUIREMENTS AND LIMITATIONS
- USERNAME (required): Cloud SQL username.
- --instance (-i) (required): Cloud SQL instance ID.
- --type (required): Cloud SQL user type; determines login authentication method. `BUILT_IN` represents a built-in user.
- --database-roles: Comma-separated roles to assign; available for MySQL and PostgreSQL. May be empty when revoking all roles.
- --revoke-existing-roles: Revoke the user's existing database roles; available for MySQL and PostgreSQL. Used with `--database-roles` to replace roles, or with an empty value to revoke all.
- --host: User hostname as an IP address, address range, or `%`; applies to MySQL and is ignored for other engines.
- Prerequisite: Custom roles must already exist in the database; create them with `CREATE ROLE` before assigning them.
- Applies to Postgres and MySQL users.
FIRST-PARTY EVIDENCE
- https://docs.cloud.google.com/sdk/docs/release-notes#55500_2026-02-03
- https://docs.cloud.google.com/sdk/gcloud/reference/sql/users/assign-roles
- https://docs.cloud.google.com/sql/docs/postgres/create-manage-users
Check the installed version and the source before using it. Entry JSON