# Database browser and SQL

URL: https://docs.vaultpanel.net/guides/databases/sql-client

> Browse a database's tables, rows and structure and run SQL inside the panel, read-only by default and confined to that one database.

Open a database to see its tables, browse rows and run SQL without leaving the panel. Everything runs
as an account that can reach only that database, so a query can never touch another database, the
MariaDB system tables or the server's files.

It needs the `databases.manage` permission (owners and admins, and hosting customers for their own
databases) and agent 0.12.0 or newer.

## Open a database

On **Databases**, click a database's name or its **Open** button. Only active databases created in
the panel can be opened; databases made outside it are not listed.

The **Tables** list on the left shows each table with its approximate row count. Click a table to
open it.

## Browse

The **Browse** tab shows a table's rows, 50 per page by default (25, 50, 100 or 250 with the
rows-per-page selector). `NULL` values show as a grey _NULL_. Click a column name to sort by it, and again
to reverse the order. **CSV** downloads the page you see, and **Query** opens the **SQL** tab with a
`SELECT` for the table.

## Structure

The **Structure** tab lists the table's columns (type, null, key, default, extra), its indexes, and
its `CREATE TABLE` statement with a copy button.

## Run SQL

The **SQL** tab runs one or more statements. Press **Ctrl + Enter** to run them. Each `SELECT` shows
its own result, and each change shows how many rows it affected.

### Read-only by default

With **Allow changes** off, the SQL runs as the database's read-only account (`SELECT` and
`SHOW VIEW`). An `UPDATE` or `DELETE` fails with a hint to turn changes on.

### Allow changes

Tick **Allow changes** to run `INSERT`, `UPDATE`, `DELETE`, `CREATE` and `DROP`, in this database
only. SQL that drops, deletes, truncates or alters asks for confirmation first, because it cannot be
undone without a backup. Every query run with changes allowed is recorded in the audit log as
`database.query`, with its SQL.

## Limits

| Limit | Value |
| --- | --- |
| Rows per result | The first 1,000 rows |
| Characters per cell | 5,000; longer values are cut |
| SQL per run | 100,000 characters |
| Time per statement | 30 seconds |

## How it is kept safe

Each database has two accounts of its own that the agent creates and keeps up to date: one that can
only read it and one with full access to it, and to nothing else on the server. Each allows at most
5 connections. The SQL you type runs as one of them, never as the database administrator, so
`SELECT * FROM mysql.user`, tables in other databases and `SELECT ... INTO OUTFILE` are denied.

The MariaDB client runs as the unprivileged `nobody` user and, where the client supports it, in
sandbox mode, so client commands such as `\! id` cannot reach the server either.

> **Tip:**
  Prefer phpMyAdmin's import and export screens? See [phpMyAdmin](https://docs.vaultpanel.net/guides/databases/phpmyadmin).
