> 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

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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.smaq.io/documentation/connections/sql-databases/gcp-cloud-sql.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
