gcloud-sql-export-sql
Export SQL database to a Cloud Storage bucket
TLDR
Export data from a specific Cloud SQL instance to a Google Cloud Storage bucket as an SQL dump file
Export data asynchronously, returning immediately without waiting for the operation to complete
Export data from specific databases within the Cloud SQL instance
Export specific tables from a specified database within the Cloud SQL instance
Export data while offloading the operation to a temporary instance to reduce strain on the source instance
Export data and compress the output with gzip
SYNOPSIS
gcloud sql export sql INSTANCE_NAME URI [--async] [--compression=COMPRESSED|NONE] [--database=DATABASE] [--offload] [--project=PROJECT_ID] [--quiet] [--verbosity=LEVEL]
PARAMETERS
INSTANCE_NAME
Name of the Cloud SQL instance to export (positional, required)
URI
GCS path for export file, e.g., gs://bucket/export.sql.gz (positional, required)
--async
Export asynchronously; returns immediately without waiting for completion
--compression=COMPRESSED|NONE
Compression type; COMPRESSED (default, gzip) or NONE
--database=DATABASE
Specific database to export; defaults to all if omitted
--offload
Offload export to a temporary server to reduce load on primary instance (beta for some DBs)
--project=PROJECT_ID
Google Cloud project ID
--quiet
Disable most output and prompts
--verbosity=debug|info|warning|error|critical
Logging verbosity level; default warning
DESCRIPTION
The gcloud sql export sql command exports data from a Cloud SQL instance (MySQL, PostgreSQL, or SQL Server) to a SQL-formatted dump file stored in a Google Cloud Storage (GCS) bucket. This logical export includes database schema, structure, and data, making it ideal for backups, disaster recovery, migrations to other databases, or local analysis.
It performs the export by connecting to the instance and generating a standard SQL file (gzip-compressed by default). Exports can target specific databases with --database, and use --offload to run the export server-side, minimizing impact on the primary instance. Asynchronous mode (--async) allows non-blocking operation.
Requires appropriate IAM permissions (cloudsql.instances.export, storage.buckets.update) and a running instance. The resulting file is compatible with import tools like gcloud sql import sql or native database clients. Large databases may take time proportional to size; monitor via Cloud SQL logs.
CAVEATS
Export fails if instance not running or lacks export permissions. SQL Server supports schema-only. Offload unavailable for read replicas. Large exports (>100GB) may timeout; use --async. File overwritten if exists.
PREREQUISITES
Install gcloud CLI; auth with gcloud auth login; enable Cloud SQL Admin API.
EXAMPLE
gcloud sql export sql my-instance gs://my-bucket/backup.sql.gz --database=prod --offload --async
Exports prod DB asynchronously.
HISTORY
Introduced in Google Cloud SDK v150+ (2017) with Cloud SQL v1; enhanced in v300+ for offload and SQL Server support. Tracks Cloud SQL GA features.


