Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Configurar o acesso à instância do Cloud SQL
Este documento fornece etapas detalhadas para configurar o peering de nuvem privada virtual, instalar um proxy do Cloud SQL e se conectar a um endereço IP interno do Cloud SQL em diferentes Google Cloud projetos.
Essa configuração garante uma comunicação eficiente e com mais segurança entre a instância do Cloud SQL e os seguintes conectores:
Este documento também aborda a criação de um anexo de rede no projeto do conector do serviço de transferência de dados do BigQuery.
Antes de começar
Verifique se você tem o seguinte:
Acesso a um Google Cloud projeto com o conector do serviço de transferência de dados do BigQuery
e outro Google Cloud projeto com a instância do Cloud SQL.
Um banco de dados MySQL ou PostgreSQL em um Google Cloud projeto.
Para configurar o peering de VPC, crie o peering de VPC no projeto do conector do serviço de transferência de dados do BigQuery, crie o peering de VPC no projeto do banco de dados do Cloud SQL para o projeto do serviço de transferência de dados do BigQuery e configure as rotas e as regras de firewall.
Criar peering de VPC no projeto do conector do serviço de transferência de dados do BigQuery
No Google Cloud console, acesse a página Peering de rede VPC do seu projeto de conector do serviço de transferência de dados do BigQuery.
No campo Nome, digite um nome para sua configuração de peering.
Em Sua rede VPC, selecione a rede VPC que você quer parear no projeto do conector do serviço de transferência de dados do BigQuery.
Em Rede VPC com peering, selecione a opção Em outro projeto.
Em ID do projeto, insira o ID do projeto do Cloud SQL.
Em Nome da rede VPC, insira o nome da rede VPC no projeto do Cloud SQL.
Clique em Criar.
Criar peering de VPC no projeto do banco de dados do Cloud SQL
Para criar o peering de VPC no projeto do banco de dados do Cloud SQL
para o projeto do serviço de transferência de dados do BigQuery, faça o seguinte:
No Google Cloud console, acesse a página Peering de rede VPC do seu projeto de conector do serviço de transferência de dados do BigQuery.
Crie regras de firewall para permitir o tráfego nas portas necessárias (por
exemplo, a porta 3306 para o MySQL e a porta 5432 para o PostgreSQL)
entre as redes com peering.
Adicione as regras de firewall personalizadas necessárias do projeto do conector do serviço de transferência de dados do BigQuery ao projeto hospedado no banco de dados do Cloud SQL.
Configure rotas e regras de firewall para seu projeto com a
instância do Cloud SQL, como fez nas etapas anteriores.
Configurar o proxy do Cloud SQL
Use o SSH para se conectar a uma instância de máquina virtual (VM) no projeto do conector do serviço de transferência de dados do BigQuery.
Atualize as permissões dos arquivos transferidos por download:
chmod+xcloud_sql_proxy
Execute o proxy do Cloud SQL:
./cloud_sql_proxy-instances=NAME=tcp:3306or5432&
Substitua NAME pelo nome da sua conexão de instância do Cloud SQL.
Conectar-se ao endereço IP interno do Cloud SQL
Use o endereço IP interno da instância do Cloud SQL para conexões.
Configure seu aplicativo ou ferramenta para se conectar ao endereço IP interno,
especificando as credenciais e os detalhes do banco de dados apropriados.
Ao se conectar de um projeto Google Cloud diferente, use o endereço IP interno da VM de proxy que você implantou anteriormente. Essa solução resolve
problemas de peering transitivo.
Criar o anexo de rede
Para criar o anexo de rede no projeto do conector do serviço de transferência de dados do BigQuery, siga estas etapas:
No Google Cloud console, acesse a página Anexos de rede.
Em Região, especifique a região em que o conector do serviço de transferência de dados do BigQuery está localizado.
Em Sub-rede, selecione a opção adequada para sua configuração.
Clique em Criar anexo de rede.
Testar a conexão
Verifique se a VM com o proxy do Cloud SQL pode se conectar à instância do Cloud SQL:
mysql-uUSERNAME-p-hIP_ADDRESS
Substitua:
USERNAME: o nome de usuário do usuário do banco de dados
IP_ADDRESS: o endereço IP da instância do Cloud SQL
Verifique se os aplicativos no projeto do conector do serviço de transferência de dados do BigQuery podem se conectar à instância do Cloud SQL usando o IP interno.
Resolver problemas
Se você tiver problemas para configurar a rede, faça o seguinte:
Verifique se o peering de VPC está estabelecido e se as rotas estão
corretamente configuradas.
Verifique se as regras de firewall permitem o tráfego nas portas necessárias.
Verifique se há erros nos registros do proxy do Cloud SQL e se ele está sendo executado
corretamente.
Verifique se a conexão de rede está configurada e conectada corretamente.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-17 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."]]