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

# Tutorial: MySQL over Live JDBC

> Query Rfam and Ensembl, real public MySQL databases, end to end — first unpaged, then cursor-paged

This tutorial runs real queries against **Rfam**, the public MySQL database of RNA families operated by EMBL-EBI, with **Ensembl**'s public server as a second example. Both are officially public with published credentials, so you can reproduce every call here exactly — RWS QA runs these very queries against the deployed service.

| | Rfam | Ensembl |
| - | - | - |
| Engine | MySQL 5.6 | MySQL 5.6 |
| JDBC URL | `jdbc:mysql://mysql-rfam-public.ebi.ac.uk:4497/Rfam` | `jdbc:mysql://ensembldb.ensembl.org:3306/` |
| User | `rfamro` | `anonymous` |
| Password | none | none |

## Prerequisites

* The `RWS Connect Live JDBC` connection from the [Live JDBC reference](https://docs.rwsintegration.com/en/features/connections/databases.md), with your `x-api-key`
* `x_db_password` always names a stored credential — for a passwordless public user, RWS stores an **empty** credential once (e.g. `PUBLIC_NO_PASSWORD`); email [connect@rwsintegration.com](mailto:connect@rwsintegration.com)

## Step 1: A first unpaged query

Count Rfam's RNA families:

| Parameter | Value |
| - | - |
| `x_jdbc_url` | `jdbc:mysql://mysql-rfam-public.ebi.ac.uk:4497/Rfam` |
| `x_db_user` | `rfamro` |
| `x_db_password` | `PUBLIC_NO_PASSWORD` |
| `x_sql` | `SELECT COUNT(*) AS families FROM family` |

```bash theme={null}
curl -G "https://connect.rwsintegration.com/v1/live/jdbc" \
  -H "x-api-key: $RWS_CONNECT_API_KEY" \
  --data-urlencode "x_jdbc_url=jdbc:mysql://mysql-rfam-public.ebi.ac.uk:4497/Rfam" \
  --data-urlencode "x_db_user=rfamro" \
  --data-urlencode "x_db_password=PUBLIC_NO_PASSWORD" \
  --data-urlencode "x_sql=SELECT COUNT(*) AS families FROM family"
```

```json theme={null}
{ "items": [ { "families": "4227" } ] }
```

The count is a string — like every value in the [response contract](https://docs.rwsintegration.com/en/features/connections/databases.md#the-response).

## Step 2: Paginate with a cursor

The `family` table's 4,227 rows fit under the 5,000-row unpaged cap, but it makes a perfect paging exercise with verifiable totals. `rfam_acc` is the primary key — the unique key paging needs:

| Parameter | Value |
| - | - |
| `x_sql` | `SELECT rfam_acc, rfam_id, updated FROM family` |
| `x_pagination` | `cursor` |
| `x_unique_keys` | `rfam_acc` |
| `x_page_size` | `1000` |

The first call carries no `x_cursor`; each response's `next_cursor` feeds the next call, until it comes back `null`. In the RWS Application, the cursor pagination config from the [Live JDBC reference](https://docs.rwsintegration.com/en/features/connections/databases.md#pagination) drives the loop for you.

Verified result on the live service: **4,227 rows in 5 pages of up to 1,000 — 4,227 distinct accessions, no duplicates, no gaps** (offset mode returns the identical set). The `updated` column is a MySQL `TIMESTAMP` and arrives as an ISO string.

> [!NOTE]
>
> A trailing `-- comment` at the end of `x_sql` is safe: the pagination wrapper puts its closing parenthesis on a new line, so the comment can't swallow it. Verified with this exact query.

## The Ensembl variant

Ensembl's public server answers the same way — only the URL and user change:

| Parameter | Value |
| - | - |
| `x_jdbc_url` | `jdbc:mysql://ensembldb.ensembl.org:3306/` |
| `x_db_user` | `anonymous` |
| `x_db_password` | `PUBLIC_NO_PASSWORD` |
| `x_sql` | `SELECT VERSION() AS version` |

Note the URL names no database — pick one per query with fully qualified table names, or put the schema in the URL. `DECIMAL` and `DATE` columns were verified to arrive as exact strings.

## MySQL notes

* MySQL as old as 5.6 works — both public servers run it.
* Paginated queries run as a derived table with `LIMIT ... OFFSET` or a keyset `WHERE` — any valid `SELECT` without its own `ORDER BY` works.
* A non-default port travels in the URL (`:4497` above), nothing else changes.

## Next steps

> [card] [Live JDBC guide](https://docs.rwsintegration.com/en/features/connections/databases.md)
>
> The full reference: directives, pagination, errors

> [card] [MariaDB tutorial](https://docs.rwsintegration.com/en/features/connections/jdbc/mariadb.md)
>
> The same flow against the UCSC Genome Browser — and the one TLS gotcha


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.