Cloud SQL 語言連接器簡介
本頁面會摘要說明 Cloud SQL 語言連接器,以及如何搭配執行個體使用這些連接器。
Cloud SQL 語言連接器是連線至 Cloud SQL 執行個體時,提供加密和 IAM 授權的程式庫。Cloud SQL 語言連接器會代表使用者應用程式,建立與 Proxy 端伺服器的授權連線,並將該連線傳遞至應用程式的資料庫驅動程式。如果沒有網路路徑,這些設定就不會提供連往 Cloud SQL 執行個體的路徑。
Cloud SQL 語言連接器會使用用戶端元件連線至 Cloud SQL 執行個體上的 Proxy 伺服器。連接器會建立臨時憑證,授權持有者連線至伺服器端 Proxy。伺服器端 Proxy 會要求提供有效的 TLS 憑證,才能連線至 Cloud SQL 資料庫,藉此限制存取權。
Cloud SQL 支援下列 Cloud SQL 語言連接器:
Cloud SQL 建議使用 Cloud SQL 語言連接器連線至 Cloud SQL 執行個體。您也可以使用資料庫用戶端或 Cloud SQL 驗證 Proxy 連線至 Cloud SQL 執行個體。如要進一步瞭解如何連線至 Cloud SQL 執行個體,請參閱連線選項簡介。
需求條件
如果 Cloud SQL 執行個體使用共用憑證授權單位 (CA) 做為 serverCaMode
,請務必在用戶端確認您使用的 Cloud SQL 語言連接器符合下列版本需求:
如果 Cloud SQL 執行個體使用客戶管理的 CA 做為 serverCaMode
,請務必在用戶端確認使用的 Cloud SQL 語言連接器符合下列版本需求:
當執行個體使用客戶管理的 CA 做為伺服器 CA 模式時,您可以為執行個體設定自訂 DNS 名稱。您可以在伺服器憑證的自訂主體別名 (SAN) 欄位中提供自訂 DNS 名稱。
為執行個體設定自訂 DNS 名稱後,您可以使用 DNS 名稱,透過 Cloud SQL 語言連接器連線至執行個體。
Cloud SQL 語言連接器的優點
使用 Cloud SQL 語言連接器連線至 Cloud SQL 執行個體,可享有下列優點:
- IAM 授權:使用 Identity and Access Management (IAM) 權限,控管哪些使用者或服務可以連線至 Cloud SQL 執行個體。
- 便利性:免除管理 SSL 憑證、設定防火牆規則或啟用授權網路的需求。
限制
如果您使用情境感知存取權和 IAM 資料庫驗證,就無法使用 Cloud SQL 語言連接器。嘗試登入執行個體時,IAM 驗證失敗。
強制使用 Cloud SQL 語言連接器
透過連接器強制執行,您可以強制規定只能使用 Cloud SQL Auth Proxy 或 Cloud SQL 語言連接器連線至 Cloud SQL 執行個體。強制執行連接器後,Cloud SQL 會拒絕直接連線至資料庫。
如果您使用已啟用 Private Service Connect 的執行個體,則會受到限制。如果執行個體已啟用連接器強制執行功能,您就無法為該執行個體建立唯讀備用資源。同樣地,如果執行個體有唯讀備用資源,您就無法為該執行個體啟用連接器強制執行功能。
如要進一步瞭解如何強制僅使用 Cloud SQL Auth Proxy 或 Cloud SQL 語言連接器連線至執行個體,請參閱「使用 Cloud SQL 語言連接器連線」。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-03 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-03 (世界標準時間)。"],[],[],null,["# Cloud SQL Language Connectors overview\n\n\u003cbr /\u003e\n\nMySQL \\| [PostgreSQL](/sql/docs/postgres/language-connectors \"View this page for the PostgreSQL database engine\") \\| [SQL Server](/sql/docs/sqlserver/language-connectors \"View this page for the SQL Server database engine\")\n\n\u003cbr /\u003e\n\nThis page summarizes the Cloud SQL Language Connectors and how to use them\nwith your instances.\n\nCloud SQL Language Connectors are libraries that provide encryption and\n[IAM](/iam) authorization when connecting to a Cloud SQL instance.\nCloud SQL Language Connectors create authorized connections to the\nproxy-side server on behalf of a user's application and pass that connection to\nthe application's database driver. They don't provide a network path to a\nCloud SQL instance if one is not already present.\n\nCloud SQL Language Connectors use a client-side component to connect to a proxy server\non the Cloud SQL instance. The connector creates a temporary certificate\nthat authorizes the holder to connect to the server-side proxy. The server-side\nproxy limits access to the Cloud SQL database by requiring a valid TLS\ncertificate in order to connect.\n\nCloud SQL supports the following Cloud SQL Language Connectors:\n\n- [Cloud SQL Java connector](/sql/docs/mysql/connect-connectors#java)\n- [Cloud SQL Python connector](/sql/docs/mysql/connect-connectors#python)\n- [Cloud SQL Go connector](/sql/docs/mysql/connect-connectors#go)\n- [Cloud SQL Node.js connector](/static/sql/docs/mysql/connect-connectors#node.js)\n\nCloud SQL recommends using Cloud SQL Language Connectors to connect to your\nCloud SQL instance. You can also connect to a Cloud SQL\ninstance [using a database client](/sql/docs/mysql/connect-admin-ip) or the\n[Cloud SQL Auth Proxy](/sql/docs/mysql/sql-proxy). For more information about\nconnecting to a Cloud SQL instance, see [About connection options](/sql/docs/mysql/connect-overview).\n\nRequirements\n------------\n\nIf your Cloud SQL instance uses\n[shared certificate authority (CA)](/sql/docs/mysql/authorize-ssl#shared-regional-ca)\nas its `serverCaMode`, then on the client side,\nmake sure that the Cloud SQL Language Connectors you're using meet\nthe following version requirements:\n\n- [Cloud SQL Java connector](/sql/docs/mysql/connect-connectors#java): [v1.21.0](https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/releases/tag/v1.21.0) or later\n- [Cloud SQL Go connector](/sql/docs/mysql/connect-connectors#go): [v1.12.0](https://github.com/GoogleCloudPlatform/cloud-sql-go-connector/releases/tag/v1.12.0) or later\n- [Cloud SQL Node.js connector](/static/sql/docs/mysql/connect-connectors#node.js): [v1.4.0](https://github.com/GoogleCloudPlatform/cloud-sql-nodejs-connector/releases/tag/v1.4.0) or later\n\n| **Note:** [Cloud SQL Python connector](/sql/docs/mysql/connect-connectors#python) supports instances that use the shared CA configuration, but the connector doesn't verify server identity.\n\nIf your Cloud SQL instance uses\n[customer-managed CA](/sql/docs/mysql/authorize-ssl#customer-managed-ca)\nas its `serverCaMode`, then on the client side,\nmake sure that the Cloud SQL Language Connectors you're using meet\nthe following version requirements:\n\n- [Cloud SQL Java connector](/sql/docs/mysql/connect-connectors#java): [v1.22.0](https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/releases/tag/v1.22.0) or later\n- [Cloud SQL Go connector](/sql/docs/mysql/connect-connectors#go): [v1.14.0](https://github.com/GoogleCloudPlatform/cloud-sql-go-connector/releases/tag/v1.14.0) or later\n- [Cloud SQL Node.js connector](/static/sql/docs/mysql/connect-connectors#node.js): [v1.6.0](https://github.com/GoogleCloudPlatform/cloud-sql-nodejs-connector/releases/tag/v1.6.0) or later\n\nWhen an instance uses customer-managed CA as its server CA mode, you can configure\nthe instance with a [custom DNS name](/sql/docs/mysql/configure-ssl-instance#custom-dns-name).\nYou provide the custom DNS name in the\ncustom subject alternative name (SAN) field of the server certificate.\n\nAfter you set up a custom DNS name for the instance, you can connect to the\ninstance from Cloud SQL Language Connectors using the DNS name.\n\nBenefits of Cloud SQL Language Connectors\n-----------------------------------------\n\nCloud SQL Language Connectors provide the following\nbenefits with connecting to a Cloud SQL instance:\n\n- **IAM authorization**: Uses identity and access management (IAM) permissions to control who or what can connect to your Cloud SQL instances.\n- **Convenience**: Removes the requirement to manage SSL certificates, configure firewall rules, or enable authorized networks.\n\n\u003cbr /\u003e\n\nLimitations\n-----------\n\nYou can't use the Cloud SQL Language Connectors if you're using\n[context-aware access](/iap/docs/cloud-iap-context-aware-access-howto) and\nIAM database authentication. When you try to login to the instance,\nIAM authentication fails.\n\nEnforce the use of Cloud SQL Language Connectors\n------------------------------------------------\n\nBy using [connector enforcement](/sql/docs/mysql/admin-api/rest/v1/instances#ConnectorEnforcement), you can enforce using only the Cloud SQL Auth Proxy or Cloud SQL Language Connectors to connect to Cloud SQL instances. With connector enforcement, Cloud SQL rejects direct connections to the database.\n\nIf you're using a [Private Service Connect-enabled instance](/sql/docs/mysql/about-private-service-connect), then there's a limitation. If the instance has connector enforcement enabled, then you can't create read replicas for the instance. Similarly, if the instance has read replicas, then you can't enable connector enforcement for the instance.\n\nFor more information about how to enforce using only the Cloud SQL Auth Proxy or Cloud SQL Language Connectors to connect to an instance, see [Connect using Cloud SQL Language Connectors](/sql/docs/mysql/connect-connectors#enforce).\n\nWhat's next\n-----------\n\n\u003cbr /\u003e\n\n- [Connect using the Cloud SQL Java Connector](/sql/docs/mysql/connect-connectors#java).\n- [Connect using the Cloud SQL Python Connector](/sql/docs/mysql/connect-connectors#python).\n- [Connect using the Cloud SQL Go Connector](/sql/docs/mysql/connect-connectors#go).\n- [Connect using the Cloud SQL Node.js Connector](/static/sql/docs/mysql/connect-connectors#node.js).\n- Learn more about the [Cloud SQL Auth Proxy](/sql/docs/mysql/sql-proxy).\n\n\u003cbr /\u003e"]]