# Connect MySQL

> Monitor MySQL and MariaDB from your Mac's notch. A read-only query checks your database on a schedule, and each new row it finds reaches you once.

Source: https://coisland.app/docs/connect-mysql/

## What you need

- **You need:** A user and its password, from Your server, or your provider’s Connect page
- **The form asks:** Host, Port, Database, Connector name, User, Password, TLS
- **You can watch:** Custom SQL, Validation
- **Access:** One SELECT, WITH or SHOW at a time, in a read-only transaction that is rolled back

To connect MySQL or MariaDB to CoIsland, you add a connector with the server's host, a database user and its password, then write a query to watch. You do it alone: any user that can sign in and read works.

CoIsland connects straight from your Mac; the password stays in your login Keychain. Every check runs inside `START TRANSACTION READ ONLY` and is rolled back, one statement at a time.

## Get a user and a password

- **Your own server:** a user with SELECT only is safest.

  ```sql
  CREATE USER 'coisland'@'%' IDENTIFIED BY 'a long password' REQUIRE SSL;
  GRANT SELECT ON shop.* TO 'coisland'@'%';
  ```

- **Amazon RDS or Aurora:** RDS console › **Databases** › your instance › **Connectivity & security**.
- **PlanetScale:** your database › **Connect** › pick the branch and a role › **Create password** (shown once). The host looks like `aws.connect.psdb.cloud`.
- **Azure Database for MySQL:** the server › **Connection strings**.
- **Google Cloud SQL:** the instance's **Connections** and **Users**.

## Connect MySQL in CoIsland

1. Open **Settings › Connectors**, click **+**, choose **MySQL**.
2. Fill in the fields as for [PostgreSQL](https://coisland.app/docs/connect-postgres/#connect-postgresql-in-coisland) (the port is 3306 unless given; the database is optional, and without one your SQL names each table as `database.table`).
3. Click **Test connector**, then **Add Connector**.

TLS works as for PostgreSQL: **verified** for PlanetScale, Azure and public certificates; **server not verified** for RDS, Cloud SQL, MariaDB's own certificate or a self-signed one; **not encrypted** only on this Mac. With TLS off, MySQL 8 asks for the whole password on the first sign-in after a restart, which CoIsland sends only over TLS: turn TLS on once.

## Watch MySQL: Custom SQL and Validation

The same two kinds as PostgreSQL. Under **Advanced**, **Database** picks another database; MySQL has no separate schema. Before anything is sent, CoIsland refuses a second statement, a write, and `INTO OUTFILE` or `INTO DUMPFILE`, which write a file on the server.

```text
-- name: Queries running over 5 minutes
-- kind: mysql.custom-sql
-- connector: shop
-- every: 5m
-- key: id

SELECT id, user, db, time, info
FROM information_schema.processlist
WHERE command <> 'Sleep' AND time > 300
```

## Troubleshooting MySQL connector errors

| Message | What to do |
|---|---|
| MySQL refused the user or the password | Check both, and the host the user is allowed from (`'user'@'%'`) |
| The server refused the sign-in: Host ... is not allowed | Ask for a user allowed from your address |
| ... insecure transport are prohibited | The server requires TLS: turn TLS on |
| this user signs in with ..., which CoIsland does not speak | Use a user on caching_sha2_password or mysql_native_password |
| Monitors only read | The SQL writes; monitors never do |
| The query ran past its time | Make it faster, or check less often |

## Frequently asked questions

### Does it work with MariaDB?

Yes: MariaDB speaks the same protocol, and its default sign-in (mysql_native_password) works.
