# Users, roles and privileges

> OpenDB uses MySQL's permission model: privileges granted to users or roles, at global, project or table level.

Source: https://www.opendb.tools/en/docs/users-roles-privileges

If you know `GRANT` and `REVOKE`, you already know OpenDB's permission model.

## The root account

The account created at installation is **root**: it holds every privilege, and nobody can delete it.

One thing is out of its reach: other users' conversations, which stay private.

## Privileges

| Family | Privileges | Possible levels |
|---|---|---|
| Data and structure | `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `ALTER`, `DROP`, `INDEX` | Global, project, table |
| Data exchange | `EXPORT`, `IMPORT` | Global, project, table |
| Structure creation | `CREATE` | Global, project |
| Features | `SEND MAIL`, `CLONE`, `MANAGE PROJECT` | Global, project |
| Administration | `CREATE PROJECT`, `MANAGE PROVIDERS`, `CREATE USER` | Global |

`ALL PRIVILEGES` stands for every privilege possible at a level.

## The three levels

| Level | Scope | MySQL equivalent |
|---|---|---|
| Global | Every project | `*.*` |
| Project | Every table of a project | `database.*` |
| Table | A single table | `database.table` |

A global privilege applies to every project. A privilege on a project applies to all its tables.

## The grant option

You can only grant the privileges you hold **with the grant option**, at the same level or a wider one. This is the equivalent of `WITH GRANT OPTION`.

The creator of a project receives every privilege on that project, with this option.

## Roles

A role is a named set of privileges. You assign it to users, who inherit them.

Three roles are created at installation.

| Role | Privileges |
|---|---|
| `admin` | Every privilege at global level, with the right to grant them |
| `développeur` | Read, write and structure on every database, exports, imports, project creation |
| `analyste` | `SELECT` and `EXPORT` on every database |

![The default roles](/images/docs/en/roles.webp)

## Manage from the interface

- **Settings → Users**: create an account, rename it, change its password, give it roles, delete it. Requires the `CREATE USER` privilege.
- **Settings → Roles**: create a role and set its privileges.
- **Project settings → Access**: grant privileges on a project. See [Share a project](/en/docs/share-a-project).

## Manage from a terminal

```bash
# Create a user with a role. The password is always asked for.
opendb user:create camille --role=analyste

# Give a role to a user, or take it away
opendb role:assign développeur camille
opendb role:assign développeur camille --revoke

# Grant SELECT and EXPORT on a project
opendb privilege:grant camille --privilege=select --privilege=export --project=shop

# Grant UPDATE on a single table, with the right to pass it on
opendb privilege:grant camille --privilege=update --project=shop --table=orders --with-grant-option

# Show a user's privileges, as GRANT statements
opendb privilege:show camille

# Revoke a privilege
opendb privilege:revoke camille --privilege=update --project=shop --table=orders
```

To act on a role rather than a user, add `--role`. Every option is in the [command reference](/en/docs/commands).

## What privileges change

- **Projects**: you only see the projects on which you hold at least one privilege.
- **Tables**: a table on which you have no privilege is out of sight, in every tab.
- **Grid**: without `UPDATE`, the grid of the Tables tab is read-only.
- **Connection secrets**: only those who can manage the project see its connection settings.

## The agent never does more than you

The agent uses the database with **your** privileges:

- it does not see the tables that are out of your sight;
- every query it writes is checked against your privileges;
- it only has the export and email tools if you are allowed to use them;
- without a write privilege, it stays read-only.

The same goes for external agents connected through the [MCP server](/en/docs/mcp-server).

## When a table is renamed or dropped

Privileges follow a renamed table. They disappear with a dropped table: a new table with the same name does not inherit them.
