> For the complete documentation index, see [llms.txt](https://docs.smaq.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.smaq.io/documentation/connections/sql-databases/gcp-cloud-sql.md).

# GCP Cloud SQL

Connect a PostgreSQL or MySQL database hosted on GCP Cloud SQL.

This guide covers the GCP-specific pieces. The SMAQ connection form is the same as any [SQL database](/documentation/connections/sql-databases.md).

### Step 1 — Collect connection details from Cloud SQL

In the GCP Console:

1. **SQL → Instances → click your instance**.
2. From the **Overview** tab, copy the **Public IP address** (or set up a Private IP — see Step 2).
3. From **Databases**, note the DB name.

> **\[Screenshot needed]** Cloud SQL instance overview with Public IP visible.

### Step 2 — Make the database reachable from SMAQ

Pick one:

* **Option A — Authorized networks** (simplest)
  1. Get SMAQ's outbound IPs from **<info@smaq.io>**.
  2. Cloud SQL instance → **Connections → Networking → Authorized networks**.
  3. Add each SMAQ IP with a descriptive name.
  4. Save.
* **Option B — Private IP + VPC peering** (enterprise) Contact <info@smaq.io>.

### Step 3 — Create a read-only DB user

Use the GCP Console (Users tab) or psql/mysql client.

**Postgres:**

```sql
CREATE USER smaq_readonly WITH PASSWORD 'long-random-string';
GRANT CONNECT ON DATABASE your_db TO smaq_readonly;
GRANT USAGE ON SCHEMA public TO smaq_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO smaq_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
  GRANT SELECT ON TABLES TO smaq_readonly;
```

**MySQL:**

```sql
CREATE USER 'smaq_readonly'@'%' IDENTIFIED BY 'long-random-string';
GRANT SELECT ON your_db.* TO 'smaq_readonly'@'%';
FLUSH PRIVILEGES;
```

### Step 4 — Add the connection in SMAQ

1. SMAQ project → **Data Source → Add data source**.
2. Pick **PostgreSQL** or **MySQL**.
3. Fill in:
   * **Host**: Cloud SQL public IP (or Private IP if using VPC peering)
   * **Port**: 5432 / 3306
   * **Database**, **Username**, **Password**
   * **SSL mode**: Require (Cloud SQL has SSL on by default)
4. **Test connection** → **Connect**.

### Troubleshooting

* **Timeout** — Cloud SQL Authorized networks doesn't include SMAQ's IPs, or the instance is set to Private IP only without peering.
* **SSL errors** — Cloud SQL exposes a server certificate. SMAQ accepts the default certificate chain; if you've enabled "Require client certificates," you'll need VPC peering instead.

### Related

* [BigQuery](/documentation/connections/sql-databases.md) — for GCP's serverless warehouse, use the BigQuery connector instead of Cloud SQL.
