Sample Header Ad - 728x90

Cloud SQL: gcloud sql export sql does not include procedures/triggers — alternatives?

1 vote
0 answers
31 views
### How to export stored procedures and triggers from Cloud SQL without hitting production? I'm using Google Cloud SQL (MySQL) and want to automate a **nightly/weekly clone** of the production database into staging. The main goal is to keep staging up to date **without impacting prod performance**. I’ve been using:
gcloud sql export sql my-instance gs://my-bucket/clone.sql.gz \
  --database=mydb \
  --offload \
  --async
This uses a temporary worker VM (serverless export) and avoids load on the main instance — which is great. However, I found that **stored procedures, triggers, and events are missing** in the dump. Attempts to add --routines, --triggers, or --events fail with:
ERROR: (gcloud.sql.export.sql) unrecognized arguments: --routines
Apparently, gcloud sql export sql **doesn't support exporting routines or triggers at all**, and there's no documented way to include them. Yet the export is still billed at $0.01/GB. --- ### Goal: Clone a Cloud SQL instance into staging, including: - Tables and schema - Data - Stored procedures / functions - Triggers - Events ...without putting load on production. --- ### Options I’ve found: 1. **gcloud sql export sql** - ✅ Offloads work (zero prod impact) - ❌ Skips procedures/triggers/events - ❌ No way to include them 2. **Direct mysqldump --routines --events --triggers on prod** - ✅ Complete dump - ❌ Impacts prod (not acceptable) 3. **Run mysqldump on a read-replica** - ✅ Complete + safe - ❌ Slightly more setup / cost --- ### Question: Is using a **read-replica + mysqldump** the only way to do a full logical export (schema + routines + triggers) **without touching prod**? Any better alternatives or official GCP-supported approaches?
Asked by scr4bble (111 rep)
Jun 2, 2025, 10:02 PM