Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menghubungkan instance Cloud Data Fusion pribadi ke
instance Cloud SQL pribadi yang menghosting database MySQL. Penyiapan serupa
berfungsi untuk instance Postgres dan SQL Server. Koneksi publik dapat dilakukan.
Direkomendasikan: Untuk alasan keamanan, gunakan instance pribadi Cloud SQL dan Cloud Data Fusion.
Membuat instance pribadi di Cloud Data Fusion dan Cloud SQL
Untuk terhubung ke instance Cloud SQL pribadi dari instance Cloud Data Fusion pribadi, Anda menggunakan VM Compute Engine proxy. Proxy
diperlukan karena jaringan Cloud SQL tidak di-peering langsung dengan jaringan Cloud Data Fusion, dan peer transitif tidak dapat saling berkomunikasi (lihat ringkasan Peering Jaringan VPC).
Untuk membuat instance pribadi, ikuti langkah-langkah berikut:
Untuk membuat VM, Anda dapat memasukkan perintah berikut di Cloud Shell atau lingkungan lain tempat Google Cloud SDK diinstal.
Perintah ini membuat VM dengan alamat IP internal dan publik
(--no-address tidak ditentukan dalam contoh perintah pembuatan VM) sehingga VM dapat mengakses Container Registry untuk mendapatkan image proxy. Anda dapat menggunakan IP internal, tetapi Anda juga harus mengaktifkan Akses Google Pribadi untuk subnet tempat VM berada.
Ekspor variabel lingkungan berikut:
exportPROJECT=CUSTOMER_PROJECTexportREGION=VM_REGIONexportZONE=`gcloudcomputezoneslist--filter="name=${REGION}"--limit1--uri--project=${PROJECT}|sed's/.*\///'`exportNETWORK=CUSTOMER_VPC_NETWORK_NAMEexportSUBNET=CUSTOMER_VPC_SUBNET_NAMEexportINSTANCE_NAME=COMPUTE_ENGINE_VM_NAMEexportSQL_CONN=SQL_INSTANCE_CONNECTION_NAMEexportCDF_IP_RANGE=CLOUD_DATA_FUSION_IP_RANGEexportVM_IMAGE=$(gcloudcomputeimageslist--project=$PROJECT--filter=family:cos-stable--format='value(selfLink.scope())'--limit=1)exportSQL_PORT=DB_PORT# MySQL 3306 # PostgreSQL 5432 # SQLServer 1433
Ganti kode berikut:
CUSTOMER_PROJECT: Nama project Anda
VM_REGION: Region tempat VM Compute Engine berada
CUSTOMER_VPC_NETWORK_NAME: Nama jaringan Anda
CUSTOMER_VPC_SUBNET_NAME: Nama subnetwork Anda
COMPUTE_ENGINE_VM_NAME: Nama VM Compute Engine
SQL_INSTANCE_CONNECTION_NAME: Nama koneksi
dari langkah sebelumnya
CLOUD_DATA_FUSION_IP_RANGE: Rentang alamat IP
DB_PORT: Nomor port database Cloud SQL
Buat aturan firewall untuk mengizinkan traffic masuk Cloud Data Fusion dengan perintah gcloud CLI berikut:
Dapatkan IP yang akan digunakan dalam string koneksi JDBC MySQL Cloud Data Fusion saat Anda menyiapkan koneksi:
echo${IP}
Setelah VM dibuat dengan IP statis, gunakan IP sebagai host atau masukkan dalam string koneksi JDBC untuk mengakses database MySQL dari Cloud Data Fusion.
Mengakses MySQL dari dalam Cloud Data Fusion
Sebelum Anda dapat terhubung ke instance MySQL dari instance Cloud Data Fusion, instal driver JDBC MySQL dari Cloud Data Fusion Hub (atau langsung dari download komunitas MySQL).
Masukkan detail koneksi untuk database MySQL Anda di Cloud Data Fusion. Anda dapat memasukkan detail dan menguji koneksi di
halaman Wrangler.
Opsional: Cara lain untuk terhubung ke MySQL
Anda dapat mengakses MySQL dengan cara berikut di Cloud Data Fusion:
Di halaman Studio, klik plugin sumber MySQL dan masukkan detail koneksi.
Di halaman Studio, gunakan plugin Sumber database, yang memiliki properti serupa (String koneksi, Nama pengguna, Sandi, dan Argumen Koneksi).
Koneksi lainnya
Meskipun menghubungkan instance pribadi direkomendasikan, koneksi berikut
mungkin dilakukan:
Instance Cloud Data Fusion publik ke instance Cloud SQL publik (dengan menggunakan proxy Cloud SQL publik atau mengizinkan rentang 0.0.0.0/0 di jaringan resmi). Lihat
opsi koneksi IP publik
untuk Cloud SQL.
Instance Cloud Data Fusion pribadi dan instance Cloud SQL publik (dengan menggunakan proxy Cloud SQL publik di jaringan resmi).
Instance Cloud Data Fusion publik dan instance Cloud SQL pribadi.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-04 UTC."],[[["\u003cp\u003eThis guide explains how to securely connect a private Cloud Data Fusion instance to a private Cloud SQL instance, such as MySQL, using a proxy Compute Engine VM.\u003c/p\u003e\n"],["\u003cp\u003eConnecting private instances of Cloud Data Fusion and Cloud SQL is highly recommended for enhanced security, and requires the use of VPC peering between the Cloud Data Fusion network and your project's VPC.\u003c/p\u003e\n"],["\u003cp\u003eA proxy Compute Engine VM is essential because the Cloud SQL network and Cloud Data Fusion network are not directly peered and cannot communicate transitively.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating private instances in both Cloud Data Fusion and Cloud SQL, setting up a proxy VM with a static internal IP, and configuring firewall rules to allow traffic from Cloud Data Fusion.\u003c/p\u003e\n"],["\u003cp\u003eWhile the document emphasizes private instance connections, it also briefly outlines other connection possibilities, such as using public instances, although these options are less secure.\u003c/p\u003e\n"]]],[],null,["# Connect to a Cloud SQL-MySQL source\n\nThis page describes how to connect a private Cloud Data Fusion instance to a\nprivate Cloud SQL instance that hosts a MySQL database. A similar setup\nworks for Postgres and SQL Server instances. [Public connections are possible](#other-connections).\n| **Note:** [VPC peering](/data-fusion/docs/how-to/create-private-ip#set-up-vpc-peering) is used to connect the Cloud Data Fusion network to your project's VPC. You can connect the Cloud SQL network to your project's VPC using VPC peering or VPN. \n| This page assumes that you're using VPC peering to connect the Cloud SQL network to your project's VPC. If you're using VPN, then don't perform the tasks described on this page. To establish the connection, you can use the internal IP address of the Cloud SQL instance in Cloud Data Fusion.\n\n**Recommended**: For security reasons, use\nprivate instances of Cloud SQL and Cloud Data Fusion.\n\nCreate private instances in Cloud Data Fusion and Cloud SQL\n-----------------------------------------------------------\n\nTo connect to a private Cloud SQL instance from a private\nCloud Data Fusion instance, you use a proxy Compute Engine VM. A proxy\nis required because the Cloud SQL network is not directly peered with\nthe Cloud Data Fusion network, and transitive peers cannot communicate with\neach other (see the [VPC Network Peering overview](/vpc/docs/vpc-peering)).\n\nTo create the private instances, follow these steps:\n\n1. If you don't already have one, [create a private Cloud Data Fusion\n instance](/data-fusion/docs/how-to/create-private-ip). This includes:\n\n 1. Setting up a VPC network\n 2. Allocating an IP range\n2. [Create a private Cloud SQL instance](/sql/docs/mysql/create-instance)\n in the same VPC network as your Cloud Data Fusion instance.\n\n3. After the instance is created, go to the Cloud SQL **Instances**\n page and expand the **Instance details** . In the **Connect to this\n instance** section, copy the IP and the connection name.\n\n [Go to Cloud SQL Instances](https://console.cloud.google.com/sql/instances)\n\nCreate a private Compute Engine VM\n----------------------------------\n\nTo create the VM, you can enter the following commands in\n[Cloud Shell](/shell) or another environment where the\n[Google Cloud SDK](/sdk/docs) is installed.\n\nThe commands create a VM with both internal and public IP addresses\n(`--no-address` isn't specified in the sample VM creation command) so that the\nVM can access the Container Registry to get the proxy image. You can use internal\nIPs, but you also must\n[enable Private Google Access](/vpc/docs/configure-private-google-access) for\nthe subnet where the VM is located.\n\n1. Export the following environmental variables:\n\n export PROJECT=\u003cvar translate=\"no\"\u003eCUSTOMER_PROJECT\u003c/var\u003e\n export REGION=\u003cvar translate=\"no\"\u003eVM_REGION\u003c/var\u003e\n export ZONE=`gcloud compute zones list --filter=\"name=${REGION}\" --limit 1 --uri --project=${PROJECT}| sed 's/.*\\///'`\n export NETWORK=\u003cvar translate=\"no\"\u003eCUSTOMER_VPC_NETWORK_NAME\u003c/var\u003e\n export SUBNET=\u003cvar translate=\"no\"\u003eCUSTOMER_VPC_SUBNET_NAME\u003c/var\u003e\n export INSTANCE_NAME=\u003cvar translate=\"no\"\u003eCOMPUTE_ENGINE_VM_NAME\u003c/var\u003e\n export SQL_CONN=\u003cvar translate=\"no\"\u003eSQL_INSTANCE_CONNECTION_NAME\u003c/var\u003e\n export CDF_IP_RANGE=\u003cvar translate=\"no\"\u003eCLOUD_DATA_FUSION_IP_RANGE\u003c/var\u003e\n export VM_IMAGE=$(gcloud compute images list --project=$PROJECT --filter=family:cos-stable --format='value(selfLink.scope())' --limit=1)\n export SQL_PORT=\u003cvar translate=\"no\"\u003eDB_PORT\u003c/var\u003e # MySQL 3306 # PostgreSQL 5432 # SQLServer 1433\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCUSTOMER_PROJECT\u003c/var\u003e: Your project's name\n - \u003cvar translate=\"no\"\u003eVM_REGION\u003c/var\u003e: The region where the Compute Engine VM is located\n - \u003cvar translate=\"no\"\u003eCUSTOMER_VPC_NETWORK_NAME\u003c/var\u003e: Your network's name\n - \u003cvar translate=\"no\"\u003eCUSTOMER_VPC_SUBNET_NAME\u003c/var\u003e: Your subnetwork's name\n - \u003cvar translate=\"no\"\u003eCOMPUTE_ENGINE_VM_NAME\u003c/var\u003e: The name of the Compute Engine VM\n - \u003cvar translate=\"no\"\u003eSQL_INSTANCE_CONNECTION_NAME\u003c/var\u003e: The connection name from the previous step\n - \u003cvar translate=\"no\"\u003eCLOUD_DATA_FUSION_IP_RANGE\u003c/var\u003e: The IP address range\n - \u003cvar translate=\"no\"\u003eDB_PORT\u003c/var\u003e: The port number of the Cloud SQL database\n2. Create a firewall rule to allow Cloud Data Fusion ingress traffic with\n the following gcloud CLI command:\n\n gcloud compute firewall-rules create allow-private-cdf \\\n --allow=tcp:22,tcp:${SQL_PORT} \\\n --source-ranges=$CDF_IP_RANGE --network=$NETWORK --project=$PROJECT\n\n3. Create the VM with the following gcloud CLI command:\n\n gcloud compute --project=${PROJECT} instances create ${INSTANCE_NAME} \\\n --zone=${ZONE} \\\n --machine-type=g1-small \\\n --subnet=${SUBNET} \\\n --metadata=startup-script=\"docker run -d -p 0.0.0.0:${SQL_PORT}:${SQL_PORT} gcr.io/cloudsql-docker/gce-proxy:latest /cloud_sql_proxy -instances=${SQL_CONN}=tcp:0.0.0.0:${SQL_PORT}\" \\\n --maintenance-policy=MIGRATE \\\n --scopes=https://www.googleapis.com/auth/cloud-platform \\\n --image=${VM_IMAGE} \\\n --image-project=cos-cloud\n\n4. Get the VM internal IP with the following gcloud CLI command:\n\n export IP=`gcloud compute \\\n --project=${PROJECT} instances describe ${INSTANCE_NAME} \\\n --zone ${ZONE} | grep \"networkIP\" | awk '{print $2}'`\n\n5. Promote the VM internal IP to a static IP with the following\n gcloud CLI command:\n\n gcloud compute --project=${PROJECT} addresses create mysql-proxy \\\n --addresses ${IP} --region ${REGION} --subnet ${SUBNET}\n\n6. Get the IP to be used in Cloud Data Fusion MySQL JDBC connection string\n when you set up the connection:\n\n echo ${IP}\n\nAfter the VM is created with a static IP, use the IP as the host or enter it in\nthe JDBC connection string to access the MySQL database from\nCloud Data Fusion.\n\nAccess MySQL from within Cloud Data Fusion\n------------------------------------------\n\nBefore you can connect to the MySQL instance from the Cloud Data Fusion\ninstance, install the MySQL JDBC driver from the Cloud Data Fusion Hub (or\ndirectly from\n[MySQL community downloads](https://dev.mysql.com/downloads/file/?id=462850)).\n| **Note:** In this case, use the general MySQL driver instead of Cloud SQL-MySQL driver.\n\nEnter the connection details for your MySQL database in\nCloud Data Fusion. You can enter the details and test the connection on\nthe **Wrangler** page.\n\n### Optional: Other ways to connect to MySQL\n\nYou can access MySQL in the following ways in Cloud Data Fusion:\n\n- On the **Studio** page, click the MySQL source plugin and enter the connection details.\n- On the **Studio** page, instead use the Database source plugin, which has\n similar properties (**Connection string** , **Username** , **Password** , and\n **Connection Arguments**).\n\n | **Note:** Unlike the MySQL plugins, the Database plugin isn't designed specifically for MySQL connections. You must understand the JDBC string format to add the connection details.\n\nOther connections\n-----------------\n\nAlthough connecting private instances is recommended, the following connections\nare possible:\n\n- A public Cloud Data Fusion instance to a public Cloud SQL instance (by using a public Cloud SQL proxy or allowlisting the `0.0.0.0/0` range in an authorized network). See the [public IP connection option](https://cloud.google.com/sql/docs/mysql/connect-overview#public_ip) for Cloud SQL.\n- A private Cloud Data Fusion instance and public Cloud SQL instance (by using a public Cloud SQL proxy in an authorized network).\n- A public Cloud Data Fusion instance and a private Cloud SQL\n instance."]]