# PUT /databases/users/{name}/grants/{database}

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the databases group.

Set a database user's privileges on a database

- Who may call it: administrator, reseller, customer
- Token scope, any of: databases, all
- Answers: 200 OK

Use the exact database name. The database and the database user must belong to the same customer, and the caller must be allowed to act for that customer. MariaDB must be installed and database.enabled must be on.

Set level to full for ALL PRIVILEGES on the database, read-only for SELECT and SHOW VIEW, or custom to supply privileges such as SELECT, INSERT. The API returns 400 for an invalid level, a missing or incorrectly formatted custom privilege list, or a name or database value outside the allowed format of 1 to 64 ASCII letters, digits, or underscores. A database user outside the caller's permitted accounts is reported as not found.

UrbeStack resets the password and grants on every MariaDB account for the database user to the recorded values, including accounts for additional hosts. The response returns the updated database user in user.

## As a command

- [urbestack-database-grant-set](https://urbestack.com/docs/commands/urbestack-database-grant-set.md): Sets a database user's privileges on a named database.

## Parameters

- `name` (path, DatabaseName, required)
- `database` (path, DatabaseName, required)

## Request body

JSON.

- `level` (string, one of full, read-only, custom, required)
- `privileges` (string): Comma-separated list of database-level privileges for level custom, up to 500 characters, excluding global privileges, FILE, and GRANT OPTION. Allowed privileges are SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX, REFERENCES, CREATE TEMPORARY TABLES, LOCK TABLES, CREATE VIEW, SHOW VIEW, TRIGGER, EXECUTE, CREATE ROUTINE, ALTER ROUTINE, and EVENT.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X PUT "$API/databases/users/alice/grants/alice_shop" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "level": "full",
    "privileges": "text"
  }'
```

Response, 200 OK:

```
{
  "user": {
    "created_at": "2026-09-09T10:15:00Z",
    "grants": [
      {
        "database": "alice_shop",
        "level": "full",
        "privileges": "text"
      }
    ],
    "id": 1,
    "name": "alice",
    "other_hosts": [
      "text"
    ],
    "updated_at": "text",
    "user": "alice",
    "user_id": 2
  }
}
```

## Errors

- 400: --name, --database and --level are required
- 400: <db.name> is <db.user>'s and <name> is <user>'s: a user is granted only databases of the same customer
- 400: A <what> name is 1 to 64 letters, digits or underscores
- 400: A custom grant needs a privilege list of names separated by commas: SELECT, INSERT, ...
- 400: The level is full, read-only or custom
- 401: Authentication required
- 404: No such database user: 
- 404: No such database: 
