# Database

[← Back to README](../README.md)

![Table data](images/db_data.png)

![Query results](images/db_page.png)

Before a connection string is found, the page looks like this:

![Database page, not connected](images/db_run.png)

## Connection

K3 Studio reads `mysql_connection_string` from any `.cfg` in the folder (example files are checked last) and connects **read-only by default**. Queries go through a small mysql2 helper that runs with bun.

## What you can do

- Schema tree of every table, with search
- Each table has **Data** and **Structure** tabs, a `WHERE` filter and paging
- SQL box: `Ctrl+Enter` runs it
- Results grid with sortable columns, **Explain** and **Copy CSV**
- Recent queries
- **Safe mode**: writes need the Writes switch turned on, and then a confirm for each statement

## SQL everywhere

![SQL box with colors and completion](images/db_colors.png)

The SQL box is colored like a `.sql` file and suggests tables, columns and keywords as you type (`Tab` takes one).

![SQL file](images/sql.png)

`.sql` files are highlighted, and completion knows your schema (tables, columns, keywords). This works in the Database SQL box and inside `MySQL.query` / oxmysql strings in both Lua and TypeScript.
