Cloud SQL for MySQL Source
3 minute read
About
Cloud SQL for MySQL is a fully-managed database service that helps you set up, maintain, manage, and administer your MySQL relational databases on Google Cloud Platform.
If you are new to Cloud SQL for MySQL, you can try creating and connecting to a database by following these instructions.
Available Tools
Cloud SQL for MySQL Source maintains full compatibility with MySQL Source, allowing you to use the following tools with your Cloud SQL for MySQL Source source:
| Tool Name | Description |
|---|---|
| mysql-execute-sql Tool | A "mysql-execute-sql" tool executes a SQL statement against a MySQL database. |
| mysql-get-query-plan Tool | A "mysql-get-query-plan" tool gets the execution plan for a SQL statement against a MySQL database. |
| mysql-list-active-queries Tool | A "mysql-list-active-queries" tool lists active queries in a MySQL database. |
| mysql-list-table-fragmentation Tool | A "mysql-list-table-fragmentation" tool lists top N fragemented tables in MySQL. |
| mysql-list-tables Tool | The "mysql-list-tables" tool lists schema information for all or specified tables in a MySQL database. |
| mysql-list-tables-missing-unique-indexes Tool | A "mysql-list-tables-missing-unique-indexes" tool lists tables that do not have primary or unique indices in a MySQL instance. |
| mysql-sql Tool | A "mysql-sql" tool executes a pre-defined SQL statement against a MySQL database. |
Pre-built Configurations
- Cloud SQL for MySQL using MCP Connect your IDE to Cloud SQL for MySQL using Toolbox.
Requirements
IAM Permissions
By default, this source uses the Cloud SQL Go Connector to authorize and establish mTLS connections to your Cloud SQL instance. The Go connector uses your Application Default Credentials (ADC) to authorize your connection to Cloud SQL.
In addition to setting the ADC for your server, you need to ensure the IAM identity has been given the following IAM roles (or corresponding permissions):
roles/cloudsql.client
Tip
If you are connecting from Compute Engine, make sure your VM also has the proper scope to connect using the Cloud SQL Admin API.
Networking
Cloud SQL supports connecting over both from external networks via the internet (public IP), and internal networks (private IP). For more information on choosing between the two options, see the Cloud SQL page Connection overview.
You can configure the ipType parameter in your source configuration to
public or private to match your cluster’s configuration. Regardless of which
you choose, all connections use IAM-based authorization and are encrypted with
mTLS.
Authentication
This source supports both password-based authentication and IAM authentication (using your Application Default Credentials).
Standard Authentication
To connect using user/password, create
a MySQL user and input your credentials in the user and
password fields.
user: ${USER_NAME}
password: ${PASSWORD}
IAM Authentication
To connect using IAM authentication:
Prepare your database instance and user following this guide.
You could choose one of the two ways to log in:
- Specify your IAM email as the
user. - Leave your
userfield blank. Toolbox will fetch the ADC automatically and log in using the email associated with it.
- Specify your IAM email as the
Leave the
passwordfield blank.
Example
kind: sources
name: my-cloud-sql-mysql-source
type: cloud-sql-mysql
project: my-project-id
region: us-central1
instance: my-instance
database: my_db
user: ${USER_NAME}
password: ${PASSWORD}
# ipType: "private"
Tip
Use environment variable replacement with the format ${ENV_NAME} instead of hardcoding your secrets into the configuration file.
Reference
| field | type | required | description |
|---|---|---|---|
| type | string | true | Must be “cloud-sql-mysql”. |
| project | string | true | Id of the GCP project that the cluster was created in (e.g. “my-project-id”). |
| region | string | true | Name of the GCP region that the cluster was created in (e.g. “us-central1”). |
| instance | string | true | Name of the Cloud SQL instance within the cluster (e.g. “my-instance”). |
| database | string | true | Name of the MySQL database to connect to (e.g. “my_db”). |
| user | string | false | Name of the MySQL user to connect as (e.g “my-mysql-user”). Defaults to IAM auth using ADC email if unspecified. |
| password | string | false | Password of the MySQL user (e.g. “my-password”). Defaults to attempting IAM authentication if unspecified. |
| ipType | string | false | IP Type of the Cloud SQL instance, must be either public, private, or psc. Default: public. |
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.