This document provides detailed steps for setting up Virtual Private Cloud peering,
installing a Cloud SQL proxy, and connecting to an internal
Cloud SQL IP address across different Trusted Cloud projects.
This setup ensures security-enhanced and efficient communication between your
Cloud SQL instance and the following connectors:
This document also covers the creation of a network attachment in the
BigQuery Data Transfer Service connector project.
Before you begin
Ensure you have the following:
- Access to a Trusted Cloud project with the BigQuery Data Transfer Service
connector and another Trusted Cloud project with the Cloud SQL instance.
- An existing MySQL or PostgreSQL database in a Trusted Cloud project.
- The appropriate permissions to
create a VPC,
create firewall rules,
and install software.
- A virtual machine (VM) instance.
Set up VPC peering
To set up VPC peering, you must create VPC
peering from the BigQuery Data Transfer Service connector
project, create VPC peering in the Cloud SQL database
project to the BigQuery Data Transfer Service project, and configure the routes and
firewall rules.
Create VPC peering from the BigQuery Data Transfer Service connector project
In the Trusted Cloud console, go to the VPC network peering page for your
BigQuery Data Transfer Service connector project.
Go to VPC Network Peering
Click add Create peering connection.
In the Name field, enter a name for your peering configuration.
For Your VPC network, select the VPC network that you want
to peer in the BigQuery Data Transfer Service connector project.
For Peered VPC network, select the In another project option.
For Project ID, enter the project ID of the Cloud SQL
project.
For VPC network name, enter the name of the VPC network
in the Cloud SQL project.
Click Create.
Create VPC peering in the Cloud SQL database project
To create VPC peering in the Cloud SQL database project
to the BigQuery Data Transfer Service project, do the following:
In the Trusted Cloud console, go to the VPC Network Peering page for your
BigQuery Data Transfer Service connector project.
Go to VPC Network Peering
Click add Create peering connection.
In the Name field, enter a name for your peering configuration.
Select the VPC network that you want to peer in the
Cloud SQL database project.
For Peer project ID, enter the project ID of the
BigQuery Data Transfer Service project.
For Peered VPC network, enter the name of the VPC network
in the BigQuery Data Transfer Service connector project.
Click Create.
If you didn't select import-export routes while configuring the peering
connections earlier, follow these steps to do so now:
Go to the Routes page for your BigQuery Data Transfer Service
connector project.
Go to Routes
Ensure the routes exist to allow traffic between the peered VPC
environments.
Go to the Firewall policies page.
Go to Firewall policies
Create firewall rules to allow for traffic on the necessary ports (for
example, port 3306 for MySQL and port 5432 for PostgreSQL)
between the peered networks.
Add the custom firewall rules that are required from the BigQuery Data Transfer Service
connector project to the Cloud SQL database-hosted
project.
Configure routes and firewall rules for your project with the
Cloud SQL instance as you did in the previous steps.
Set up the Cloud SQL proxy
Use SSH to connect to a virtual machine (VM) instance in the
BigQuery Data Transfer Service connector project.
In the terminal, download the Cloud SQL proxy:
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
Update the permissions for the downloaded files:
chmod +x cloud_sql_proxy
Run the Cloud SQL proxy:
./cloud_sql_proxy -instances=NAME=tcp:3306 or 5432 &
Replace NAME
with the name of your
Cloud SQL instance connection.
Connect to the internal Cloud SQL IP address
- Use the internal IP address of the Cloud SQL instance for connections.
- Configure your application or tool to connect to the internal IP address,
specifying the appropriate credentials and database details.
When connecting from a different Trusted Cloud project, use the internal
IP address of the proxy VM that you deployed earlier. This solution resolves
transitive peering issues.
Create the network attachment
To create the network attachment in the BigQuery Data Transfer Service connector
project, follow these steps:
In the Trusted Cloud console, go to the Network attachments page.
Go to Network attachments
Click add Create network attachment.
Provide a name for the network attachment.
Select the appropriate VPC network.
For Region, specify the region where your BigQuery Data Transfer Service connector is located.
For Subnetwork, select the appropriate option that matches your setup.
Click Create network attachment.
Test the connection
Verify that the VM with the Cloud SQL proxy can connect to the
Cloud SQL instance:
mysql -u USERNAME -p -h IP_ADDRESS
Replace the following:
USERNAME
: the username of the database user
IP_ADDRESS
: the IP address of the Cloud SQL instance
Ensure that applications in the BigQuery Data Transfer Service connector
project can connect to the Cloud SQL instance using the internal IP.
Troubleshoot
If you are having issues setting up your network configuration, do the following:
- Ensure that VPC peering is established and that routes are
correctly configured.
- Verify that the firewall rules allow for traffic on the required ports.
- Check the Cloud SQL proxy logs for errors and ensure it is running
correctly.
- Ensure that the network attachment is correctly configured and connected.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-25 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThis guide details how to configure secure access to a Cloud SQL instance from the BigQuery Data Transfer Service across separate Google Cloud projects using Virtual Private Cloud (VPC) peering.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves setting up VPC peering from both the BigQuery Data Transfer Service connector project and the Cloud SQL database project, ensuring proper route configuration, and creating firewall rules.\u003c/p\u003e\n"],["\u003cp\u003eSetting up the Cloud SQL proxy on a virtual machine (VM) within the BigQuery Data Transfer Service connector project is necessary for connecting to the internal Cloud SQL IP address.\u003c/p\u003e\n"],["\u003cp\u003eA network attachment needs to be created in the BigQuery Data Transfer Service connector project, specifying the appropriate VPC network, region, and subnetwork.\u003c/p\u003e\n"],["\u003cp\u003eAfter configuration, the guide emphasizes the importance of testing the connection to ensure that the VM hosting the Cloud SQL proxy can reach the Cloud SQL instance and that applications within the BigQuery Data Transfer Service project can connect using the internal IP.\u003c/p\u003e\n"]]],[],null,["# Configure Cloud SQL instance access\n===================================\n\nThis document provides detailed steps for setting up Virtual Private Cloud peering,\ninstalling a Cloud SQL proxy, and connecting to an internal\nCloud SQL IP address across different Google Cloud projects.\nThis setup ensures security-enhanced and efficient communication between your\nCloud SQL instance and the following connectors:\n\n- [The BigQuery Data Transfer Service MySQL connector](/bigquery/docs/mysql-transfer)\n- [The BigQuery Data Transfer Service PostgreSQL connector](/bigquery/docs/postgresql-transfer).\n\nThis document also covers the creation of a network attachment in the\nBigQuery Data Transfer Service connector project.\n\nBefore you begin\n----------------\n\nEnsure you have the following:\n\n- Access to a Google Cloud project with the BigQuery Data Transfer Service connector and another Google Cloud project with the Cloud SQL instance.\n- An existing MySQL or PostgreSQL database in a Google Cloud project.\n- The appropriate permissions to [create a VPC](/vpc/docs/create-modify-vpc-networks), [create firewall rules](/network-connectivity/docs/vpn/how-to/configuring-firewall-rules), and install software.\n- A [virtual machine (VM) instance](/compute/docs/instances/create-start-instance).\n\nSet up VPC peering\n------------------\n\nTo set up VPC peering, you must create VPC\npeering from the BigQuery Data Transfer Service connector\nproject, create VPC peering in the Cloud SQL database\nproject to the BigQuery Data Transfer Service project, and configure the routes and\nfirewall rules.\n\n### Create VPC peering from the BigQuery Data Transfer Service connector project\n\n1. In the Google Cloud console, go to the **VPC network peering** page for your\n BigQuery Data Transfer Service connector project.\n\n [Go to VPC Network Peering](https://console.cloud.google.com/networking/peering/list)\n2. Click add **Create peering connection**.\n\n3. In the **Name** field, enter a name for your peering configuration.\n\n4. For **Your VPC network**, select the VPC network that you want\n to peer in the BigQuery Data Transfer Service connector project.\n\n5. For **Peered VPC network** , select the **In another project** option.\n\n6. For **Project ID**, enter the project ID of the Cloud SQL\n project.\n\n7. For **VPC network name**, enter the name of the VPC network\n in the Cloud SQL project.\n\n8. Click **Create**.\n\n### Create VPC peering in the Cloud SQL database project\n\nTo create VPC peering in the Cloud SQL database project\nto the BigQuery Data Transfer Service project, do the following:\n\n1. In the Google Cloud console, go to the **VPC Network Peering** page for your\n BigQuery Data Transfer Service connector project.\n\n [Go to VPC Network Peering](https://console.cloud.google.com/networking/peering/list)\n2. Click add **Create peering connection**.\n\n3. In the **Name** field, enter a name for your peering configuration.\n\n4. Select the VPC network that you want to peer in the\n Cloud SQL database project.\n\n5. For **Peer project ID**, enter the project ID of the\n BigQuery Data Transfer Service project.\n\n6. For **Peered VPC network**, enter the name of the VPC network\n in the BigQuery Data Transfer Service connector project.\n\n7. Click **Create**.\n\n### Configure routes and firewall rules\n\nIf you didn't select import-export routes while configuring the peering\nconnections earlier, follow these steps to do so now:\n\n1. Go to the **Routes** page for your BigQuery Data Transfer Service\n connector project.\n\n [Go to Routes](https://console.cloud.google.com/networking/routes/list)\n2. Ensure the routes exist to allow traffic between the peered VPC\n environments.\n\n3. Go to the **Firewall policies** page.\n\n [Go to Firewall policies](https://console.cloud.google.com/networking/firewalls/list)\n4. Create firewall rules to allow for traffic on the necessary ports (for\n example, port 3306 for MySQL and port 5432 for PostgreSQL)\n between the peered networks.\n\n5. Add the custom firewall rules that are required from the BigQuery Data Transfer Service\n connector project to the Cloud SQL database-hosted\n project.\n\n6. Configure routes and firewall rules for your project with the\n Cloud SQL instance as you did in the previous steps.\n\nSet up the Cloud SQL proxy\n--------------------------\n\n1. Use SSH to connect to a virtual machine (VM) instance in the\n BigQuery Data Transfer Service connector project.\n\n2. In the terminal, download the Cloud SQL proxy:\n\n wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy\n\n3. Update the permissions for the downloaded files:\n\n chmod +x cloud_sql_proxy\n\n4. Run the Cloud SQL proxy:\n\n ./cloud_sql_proxy -instances=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nv\"\u003eNAME\u003c/span\u003e\u003c/var\u003e=tcp:3306 or 5432 &\n\n Replace \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e with the name of your\n Cloud SQL instance connection.\n\nConnect to the internal Cloud SQL IP address\n--------------------------------------------\n\n1. Use the internal IP address of the Cloud SQL instance for connections.\n2. Configure your application or tool to connect to the internal IP address, specifying the appropriate credentials and database details.\n\nWhen connecting from a different Google Cloud project, use the internal\nIP address of the proxy VM that you deployed earlier. This solution resolves\ntransitive peering issues.\n\nCreate the network attachment\n-----------------------------\n\nTo create the network attachment in the BigQuery Data Transfer Service connector\nproject, follow these steps:\n\n1. In the Google Cloud console, go to the **Network attachments** page.\n\n [Go to Network attachments](https://console.cloud.google.com/net-services/psc/list/networkAttachments)\n2. Click add **Create network attachment**.\n\n3. Provide a name for the network attachment.\n\n4. Select the appropriate VPC network.\n\n5. For **Region**, specify the region where your BigQuery Data Transfer Service connector is located.\n\n6. For **Subnetwork**, select the appropriate option that matches your setup.\n\n7. Click **Create network attachment**.\n\nTest the connection\n-------------------\n\n1. Verify that the VM with the Cloud SQL proxy can connect to the\n Cloud SQL instance:\n\n mysql -u \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e -p -h \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: the username of the database user\n - \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e: the IP address of the Cloud SQL instance\n2. Ensure that applications in the BigQuery Data Transfer Service connector\n project can connect to the Cloud SQL instance using the internal IP.\n\nTroubleshoot\n------------\n\nIf you are having issues setting up your network configuration, do the following:\n\n- Ensure that VPC peering is established and that routes are correctly configured.\n- Verify that the firewall rules allow for traffic on the required ports.\n- Check the Cloud SQL proxy logs for errors and ensure it is running correctly.\n- Ensure that the network attachment is correctly configured and connected."]]