sincecutoff.com
← all changes

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_IN
gcloud sql users assign-roles <USERNAME> --instance=<INSTANCE> --revoke-existing-roles --database-roles=<ROLE_1>,<ROLE_2> --type=BUILT_IN
gcloud sql users assign-roles <USERNAME> --type=BUILT_IN --instance=<INSTANCE> --database-roles= --revoke-existing-roles

WHY 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

Check the installed version and the source before using it. Entry JSON

Report a problem with this card