> ## Documentation Index
> Fetch the complete documentation index at: https://help.noxity.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Run SQL Queries

> Run SELECT, UPDATE, and DDL queries from phpMyAdmin's SQL tab, with bookmarks, query history, and safety tips for production data.

The SQL tab is where you'd run any query that isn't a one-row edit. It accepts any valid MySQL statement, runs it against the active database, and shows the result below.

## Open the SQL tab

<Steps>
  <Step title="Pick the scope">
    Click a database in the left tree to run queries against the whole database. Click into a specific table to scope queries to that table.
  </Step>

  <Step title="Click the SQL tab at the top">
    A multi-line text area opens with a basic syntax-highlighted editor.

    <Frame>
      <img src="https://mintlify.s3.us-west-1.amazonaws.com/noxity/images/cpanel/database-management/phpmyadmin/sql/tab-light.png" alt="phpMyAdmin SQL tab with the query editor" className="block dark:hidden" />

      <img src="https://mintlify.s3.us-west-1.amazonaws.com/noxity/images/cpanel/database-management/phpmyadmin/sql/tab-dark.png" alt="phpMyAdmin SQL tab with the query editor" className="hidden dark:block" />
    </Frame>
  </Step>

  <Step title="Type or paste your query">
    Multiple statements separated by semicolons all run in sequence. The result panel shows them stacked.
  </Step>

  <Step title="Click Go">
    The results appear under the editor. Above the results, phpMyAdmin echoes the SQL it ran. Useful for spot-checking before you re-run.
  </Step>
</Steps>

## Useful keyboard shortcuts

| Keys         | Action                              |
| ------------ | ----------------------------------- |
| `Ctrl+Enter` | Run the query (same as clicking Go) |
| `Ctrl+Space` | Auto-complete table or column names |
| `Tab`        | Indent (handy when nesting queries) |

## Bookmarks

If a query is one you'll run repeatedly, save it as a bookmark.

<Steps>
  <Step title="Type the query">
    Same as a normal run.
  </Step>

  <Step title="Tick 'Bookmark this SQL query'">
    Below the editor, just above **Go**.
  </Step>

  <Step title="Name and save">
    Give the bookmark a name. Click **Go**.
  </Step>

  <Step title="Run it later">
    On any future visit to the SQL tab, scroll down to **Bookmarked SQL query** and pick it from the dropdown. Click **Submit** to run it again.
  </Step>
</Steps>

Bookmarks are per database. Useful patterns:

* A long `JOIN` you tweak when debugging
* A `DELETE FROM sessions WHERE last_seen < NOW() - INTERVAL 30 DAY` you run before exports
* An ad-hoc analytics query for the marketing team

## Query history

The SQL tab keeps a running list of queries you've executed in the current session. Open the **Query history** dropdown above the editor to revisit them. Sessions reset when you close the browser tab, so save anything important as a bookmark.

## Safety tips for production data

<Warning>
  An `UPDATE` or `DELETE` without a `WHERE` clause hits every row. There's no undo button.
</Warning>

A few habits that have saved me:

1. **Run as `SELECT` first.** Run `SELECT * FROM users WHERE last_login < '2024-01-01'` before turning it into `DELETE FROM users WHERE last_login < '2024-01-01'`. Confirm the row count matches what you expected.
2. **Wrap in a transaction for InnoDB tables.** `START TRANSACTION;` before the `UPDATE`/`DELETE`, then `SELECT COUNT(*)` to verify, then `COMMIT;` (or `ROLLBACK;` if it's wrong). Doesn't work on MyISAM.
3. **`LIMIT` your destructive queries.** `DELETE FROM logs WHERE created_at < '2024-01-01' LIMIT 1000`, run it a few times. Easier to spot a wrong condition before you've nuked half the table.
4. **Take an [export](/web-hosting/cpanel/database-management/phpmyadmin/export) first.** Five minutes of "I'll just dump it before I touch it" can save hours of restore work later.

## Common issues

<AccordionGroup>
  <Accordion title="#1064 You have an error in your SQL syntax">
    A typo, an unclosed quote, or a backtick around something that doesn't need one. Look at the position pointed at in the error message. phpMyAdmin highlights the offending character.

    If the query was pasted from somewhere else, check for smart-quote characters that look like `'` but aren't.
  </Accordion>

  <Accordion title="#1142 SELECT command denied to user">
    The user you're running phpMyAdmin as doesn't have read access to that table. cPanel logs you in as the cPanel account user, which has access to your databases. But if you've revoked privileges through [Manage My Databases](/web-hosting/cpanel/database-management/manage-databases), this is the message you'll see.
  </Accordion>

  <Accordion title="The query runs forever and the page hangs">
    A `JOIN` on un-indexed columns, or a `LIKE '%...'` against a big text column. Either kill the query (close the browser tab and the connection drops within a minute) or add an index first via [Table Operations](/web-hosting/cpanel/database-management/phpmyadmin/table-operations).

    Repeated long-running queries from the same account can trigger our automatic resource limits. See [common issues on Manage My Databases](/web-hosting/cpanel/database-management/manage-databases#common-issues).
  </Accordion>
</AccordionGroup>

## Need a hand?

<CardGroup cols={2}>
  <Card title="Open a ticket" icon="life-ring" href="https://members.noxity.io/submitticket.php">
    Best for anything that needs an account check or a config change on our end.
  </Card>

  <Card title="Live chat" icon="messages" href="https://noxity.io/contact">
    Faster for quick questions during business hours.
  </Card>
</CardGroup>
