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

# MySQL on Square Cloud: Connection, Permissions and Limits

> Managed MySQL on Square Cloud: connection string, required TLS, caching_sha2_password, user privileges, importing dumps with DEFINER, buffer pool, slow query log and common errors.

A managed MySQL instance that only accepts TLS connections, with a user that can manage its own databases, users, routines and events. Facts shared by every engine (limits, snapshots, Insights) are on the [Databases overview](https://docs.squarecloud.app/en/services/databases.md).

## Connect

Copy the connection URL from the database's page in the dashboard. It has this shape, with the `squarecloud` user and the `squarecloud` database created for you:

```
mysql://squarecloud:PASSWORD@HOST:PORT/squarecloud
```

MySQL requires **SSL/TLS**; a client certificate is not needed. Use `ssl-mode=REQUIRED`, or `VERIFY_CA` with the `.pem` from **Connection** → **SSL/TLS certificate** as the CA to also check the server.

The server accepts only the `caching_sha2_password` authentication. Older drivers that lack it, such as the npm `mysql` package, fail to log in: use `mysql2` on Node.js or a current connector.

> [tab] Node.js
>
> ```javascript theme={"system"}
> import fs from "node:fs";
> import mysql from "mysql2/promise";
>
> // One pool for the whole process, created once and reused.
> export const pool = mysql.createPool({
>   uri: process.env.DATABASE_URL,
>   ssl: { ca: fs.readFileSync("certificate.pem", "utf8") },
>   connectionLimit: 10,
> });
>
> const [rows] = await pool.query("SELECT NOW()");
> ```

> [tab] Python
>
> ```python theme={"system"}
> import os
> from urllib.parse import urlparse, unquote
> import pymysql
>
> url = urlparse(os.environ["DATABASE_URL"])
> conn = pymysql.connect(
>     host=url.hostname,
>     port=url.port,
>     user=unquote(url.username),
>     password=unquote(url.password),
>     database=url.path.lstrip("/"),
>     ssl={"ca": "certificate.pem"},
> )
> ```

> [tab] mysql CLI
>
> ```bash theme={"system"}
> mysql --host=HOST --port=PORT --user=squarecloud --password \
>   --ssl-mode=VERIFY_CA --ssl-ca=certificate.pem squarecloud
> ```

The server does not resolve host names: when you create users, their host part is an IP address or `'%'`.

ORMs and GUI tools (Prisma, MySQL Workbench, DBeaver, HeidiSQL) are covered in [database connection errors](https://docs.squarecloud.app/en/platform/troubleshooting/database-connection-errors.md).

## Connections

Each database accepts up to 256 simultaneous connections; past that, new ones fail with `Too many connections`. Create **one pool per process** at startup and reuse it, sized so that every app, worker and shard together stays under the limit. The **Insights** tab shows who holds the open connections.

## Your user and permissions

The `squarecloud@'%'` user has every privilege, with `GRANT OPTION`, except the administrative ones. You can create databases, users and grants, routines, triggers and events, and change global variables with `SET GLOBAL` and `SET PERSIST`.

What the administrative privileges would allow is not available:

* server-side files: `LOAD DATA INFILE` and `SELECT ... INTO OUTFILE`;
* `FLUSH PRIVILEGES`, which answers `ERROR 1227`. It is not needed: `GRANT`, `CREATE USER` and `ALTER USER` apply at once;
* `SHOW ENGINE INNODB STATUS`;
* replication.

## Importing a dump

Dumps taken from another server often carry `DEFINER=root@localhost` (or another administrative account) on views, routines, triggers and events. Importing them fails with `ERROR 1227 (42000): Access denied; you need (at least one of) the ... privilege(s)`. Remove the clauses before importing, or set them to your own user:

```bash theme={"system"}
sed -E 's/DEFINER=`[^`]+`@`[^`]+`//g' dump.sql > dump-clean.sql
mysql --host=HOST --port=PORT --user=squarecloud --password \
  --ssl-mode=REQUIRED squarecloud < dump-clean.sql
```

## Configuration

* **No binary log.** Replication, change data capture (Debezium and similar) and point-in-time recovery are not available.
* **Buffer pool:** `innodb_buffer_pool_size` keeps MySQL's default of **128 MB**; it does not grow with the database's RAM. You can raise it within the RAM you allocated, leaving room for connections and the server itself (about half of the RAM is a safe start):
  ```sql theme={"system"}
  SET PERSIST innodb_buffer_pool_size = 536870912; -- 512 MB
  ```
  A persisted value is lost when the database is restored from a snapshot or upgraded: set it again afterwards.
* **`max_allowed_packet`** is 64 MB, the largest single statement or row the server accepts.
* The rest of the server configuration is the same on every database.

## Slow queries

The **Insights** tab lists statements by mean time (any statement with a run of 100 ms or more). For the raw slow query log, turn it on: it is written to the `mysql.slow_log` table at the same 100 ms threshold, never expires and uses the database's storage, so empty it when you are done:

```sql theme={"system"}
SET GLOBAL slow_query_log = ON;
SELECT start_time, query_time, sql_text FROM mysql.slow_log ORDER BY start_time DESC LIMIT 10;
TRUNCATE TABLE mysql.slow_log;
SET GLOBAL slow_query_log = OFF;
```

## Snapshots

A MySQL snapshot holds your schemas, routines, triggers, events and users, exported in a single transaction: consistent for InnoDB tables, not guaranteed for MyISAM. Besides the [general cases](https://docs.squarecloud.app/en/services/databases.md#snapshots-and-restore), it fails when your own `LOCK TABLES` blocks it for more than 5 minutes. The export is plain SQL text, so a database close to its 10 GB of storage may not fit in a snapshot.

## Common errors

| Message | What it means | What to do |
| :- | :- | :- |
| `Connections using insecure transport are prohibited while --require_secure_transport=ON` | The client connected without SSL/TLS. | Enable SSL/TLS (`ssl-mode=REQUIRED`). |
| `ER_NOT_SUPPORTED_AUTH_MODE` | The driver lacks `caching_sha2_password`. | Switch to `mysql2` or a current connector. |
| `Too many connections` | All 256 connections are in use. | Use one shared pool per process; see [Connections](#connections). |
| `ERROR 1227 (42000): Access denied; you need ... privilege(s)` | The statement needs an administrative privilege, or a dump carries `DEFINER=root`. | Drop `FLUSH PRIVILEGES`; remove the `DEFINER` clauses. |
| `Got a packet bigger than 'max_allowed_packet' bytes` | A statement or row is over 64 MB. | Split it into smaller inserts. |
| `The table '...' is full` | The 10 GB of storage is full: writes fail. | Delete data; see [disk full](https://docs.squarecloud.app/en/platform/troubleshooting/database-performance.md#the-disk-is-full). |

After a forced stop, MySQL runs its crash recovery on the next start, which takes longer on large databases: wait for it to finish.

## Contact us

If you continue facing **technical difficulties**, our **specialized support team** is available to assist you. [**Contact us**](https://squarecloud.app/en/support) and we'll be happy to help you resolve any issue: support quality is a big part of why developers rate Square Cloud [**4.9/5 across 402 reviews**](https://www.trustpilot.com/review/squarecloud.app) on Google and Trustpilot.


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