Auf dieser Seite erfahren Sie, wie Sie mithilfe des Cloud SQL Auth-Proxys von einer lokalen Testumgebung eine Verbindung zu Cloud SQL herstellen. Der Cloud SQL Auth-Proxy bietet sicheren Zugriff auf Ihre Cloud SQL-Instanz, ohne dass autorisierte Netzwerke erforderlich sind oder SSL konfiguriert werden muss. Mit dem Cloud SQL Auth-Proxy können Sie sicher eine Verbindung zu Ihrer Cloud SQL-Instanz herstellen.
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Klicken Sie auf die folgende Schaltfläche, um Cloud Shell zu öffnen, die Befehlszeilenzugriff auf Ihre Google Cloud Ressourcen direkt über den Browser bietet.
Mit Cloud Shell können Sie die in dieser Kurzanleitung vorgestellten gcloud-Befehle ausführen.
In the Principal column, find all rows that identify you or a group that
you're included in. To learn which groups you're included in, contact your
administrator.
For all rows that specify or include you, check the Role column to see whether
the list of roles includes the required roles.
Klicken Sie auf person_addZugriffsrechte erteilen.
Geben Sie im Feld Neue Hauptkonten Ihre Nutzer-ID ein.
Das ist in der Regel die E‑Mail-Adresse eines Google-Kontos.
Wählen Sie in der Liste Rolle auswählen eine Rolle aus.
Klicken Sie auf addWeitere Rolle hinzufügen, wenn Sie weitere Rollen zuweisen möchten.
Klicken Sie auf Speichern.
Cloud SQL-Instanz erstellen
In dieser Kurzanleitung verwenden Sie die Google Cloud Console. Informationen zur Verwendung der gcloud CLI, cURL oder PowerShell finden Sie unter Instanzen erstellen.
Wechseln Sie in der Google Cloud Console zur Seite Cloud SQL-Instanzen.
Geben Sie im Feld Instanz-ID den Wert myinstance ein.
Geben Sie im Feld Passwort ein Passwort für den Nutzer sqlserver ein.
Klicken Sie auf Instanz erstellen.
Sie werden zur Instanzliste zurückgeleitet. Sie können direkt auf die neue Instanz klicken, um die Details aufzurufen. Die Instanz steht jedoch erst für andere Vorgänge zur Verfügung, wenn sie initialisiert und gestartet wurde.
Debian/Ubuntu
Installieren Sie für Debian/Ubuntu die entsprechenden SQL Server-Befehlszeilentools mit diesen Anleitungen.
CentOS/RHEL
Installieren Sie für CentOS/RHEL die entsprechenden SQL Server-Befehlszeilentools mit diesen Anleitungen.
openSUSE
Installieren Sie für openSUSE die entsprechenden SQL Server-Befehlszeilentools mit diesen Anleitungen.
Klicken Sie auf den Instanznamen, um die zugehörige Seite Übersicht zu öffnen.
Kopieren Sie im Abschnitt Mit dieser Instanz verbinden den Verbindungsnamen. Der Verbindungsname hat das Format projectID:region:instanceID.
Cloud SQL Auth-Proxy starten
Starten Sie den Cloud SQL Auth-Proxy in einem eigenen Terminal, damit Sie die Ausgabe überwachen können. Ersetzen Sie INSTANCE_CONNECTION_NAME durch den Namen der Instanzverbindung, den Sie im vorherigen Schritt kopiert haben.
Verwenden Sie in Linux-Umgebungen den folgenden Befehl, um den Cloud SQL Auth-Proxy zu starten:
./cloud-sql-proxyINSTANCE_CONNECTION_NAME
Verwenden Sie in PowerShell unter Windows den folgenden Befehl, um den Cloud SQL Auth-Proxy zu starten:
.\cloud-sql-proxy.exeINSTANCE_CONNECTION_NAME
Es wird dann eine Meldung wie die folgende angezeigt:
Listening on 127.0.0.1:1433 for INSTANCE_CONNECTION_NAME
Ready for new connections
Führen Sie den folgenden Befehl aus und ersetzen Sie dabei USER_NAME durch den SQL Server-Nutzernamen.
sqlcmd-S127.0.0.1-UUSER_NAME
Kehren Sie zum Terminalfenster zurück, in dem Sie den Cloud SQL Auth-Proxy gestartet haben. Es wird eine Meldung ähnlich der folgenden angezeigt:
New connection for myInstance
Bereinigen
Mit den folgenden Schritten vermeiden Sie, dass Ihrem Google Cloud -Konto die auf dieser Seite verwendeten Ressourcen in Rechnung gestellt werden:
Wechseln Sie in der Google Cloud Console zur Seite Cloud SQL-Instanzen.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[],[],null,["# Quickstart: Connect to Cloud SQL for SQL Server using the Cloud SQL Auth Proxy\n\nConnect to Cloud SQL for SQL Server using the Cloud SQL Auth Proxy\n==================================================================\n\n\u003cbr /\u003e\n\n[MySQL](/sql/docs/mysql/quickstart-proxy-test \"View this page for the MySQL database engine\") \\| [PostgreSQL](/sql/docs/postgres/quickstart-proxy-test \"View this page for the PostgreSQL database engine\") \\| SQL Server\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page shows you how to connect to Cloud SQL from a local test\nenvironment using the Cloud SQL Auth Proxy. The [Cloud SQL Auth Proxy](/sql/docs/sqlserver/sql-proxy)\nprovides secure access to your Cloud SQL instance without the need for\nauthorized networks or for configuring SSL. By using the Cloud SQL Auth Proxy, you can\nconnect to your Cloud SQL instance securely.\n\nThe instructions on this page are for a test environment only and shouldn't be\nused for production environments. For more information\non the configuration required for production environments, see\n[Use the Cloud SQL Auth Proxy in a production environment](/sql/docs/mysql/sql-proxy#production-environment)\nand [Connect using the Cloud SQL Auth Proxy](/sql/docs/mysql/connect-auth-proxy).\n\nBefore you begin\n----------------\n\n| **Note:** The name you use for your project must be between 4 and 30 characters. When you type the name, the form suggests a project ID, which you can edit. The project ID must be between 6 and 30 characters, with a lowercase letter as the first character. You can use a dash, lowercase letter, or digit for the remaining characters, but the last character cannot be a dash.\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n1. Enable the necessary Google Cloud APIs. \n\n ### Console\n\n In the Google Cloud console, go to the **APIs** page.\n\n [Go to APIs](https://console.cloud.google.com/apis)\n Enable the Cloud SQL Admin API.\n\n ### gcloud\n\n Click the following button to open Cloud Shell, which provides\n command-line access to your Google Cloud resources directly from the browser.\n Cloud Shell can be used to run the `gcloud` commands presented throughout this quickstart.\n\n [Open Cloud Shell](/console/sql/instances?cloudshell=true)\n\n\n Run the [`gcloud services enable`](/sdk/gcloud/reference/services/enable) command\n as follows using Cloud Shell to enable the APIs required for this quickstart.:\n\n ```bash\n gcloud services enable sqladmin.googleapis.com\n ```\n\n This command enables the following APIs:\n - Cloud SQL Admin API\n2.\n\n Make sure that you have the following role or roles on the project:\n\n Cloud SQL Admin (`roles/cloudsql.admin`), Cloud SQL Viewer (`roles/cloudsql.viewer`)\n\n #### Check for the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3.\n In the **Principal** column, find all rows that identify you or a group that\n you're included in. To learn which groups you're included in, contact your\n administrator.\n\n 4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.\n\n #### Grant the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3. Click person_add **Grant access**.\n 4.\n In the **New principals** field, enter your user identifier.\n\n This is typically the email address for a Google Account.\n\n 5. In the **Select a role** list, select a role.\n 6. To grant additional roles, click add **Add\n another role** and add each additional role.\n 7. Click **Save**.\n\nCreate a Cloud SQL instance\n---------------------------\n\nIn this quickstart, you use the Google Cloud console. To use the\n[gcloud CLI](/sdk/gcloud), cURL, or PowerShell, see\n[Create instances](/sql/docs/sqlserver/create-instance).\n\n1. In the Google Cloud console, go to the **Cloud SQL Instances** page.\n\n [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)\n2. Click **Create instance**.\n3. Click **Choose SQL Server**.\n4. In the **Instance ID** field, enter `myinstance`.\n5. In the **Password** field, enter a password for the `sqlserver` user.\n6. Click **Create instance**.\n\n You're returned to the instances list. You can click the new instance right\n away to see the details, but it won't be available for other operations until\n it initializes and starts.\n | **Note:** In this example, the instance is created using default settings, including a public IP address.\n\n### Debian/Ubuntu\n\nFor Debian/Ubuntu, install the applicable SQL Server command-line tools using\n[these instructions](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-2017#ubuntu).\n\n### CentOS/RHEL\n\nFor CentOS/RHEL, install the applicable SQL Server command-line tools using\n[these instructions](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-2017#install-tools-on-rhel-7).\n\n### openSUSE\n\nFor openSUSE, install the applicable SQL Server command-line tools using\n[these instructions](https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-suse?view=sql-server-2017#tools).\n\n### Other platforms\n\nSee the [landing page](https://docs.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-database-engine?view=sql-server-2017) for installing SQL Server, as well as the\n[SQL Server downloads page](https://www.microsoft.com/en-us/sql-server/sql-server-downloads).\n\nInstall the Cloud SQL Auth Proxy client\n---------------------------------------\n\nFor installation, see\n[Installing the Cloud SQL Auth Proxy](/sql/docs/sqlserver/connect-auth-proxy#install).\n\nGet the instance connection name\n--------------------------------\n\n1. In the Google Cloud console, go to the **Cloud SQL Instances** page.\n\n [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)\n2. Click the instance name to open its **Overview** page.\n3. In the **Connect to this instance** section, copy the **Connection name** . The connection name is in the format `projectID:region:instanceID`.\n\nStart the Cloud SQL Auth Proxy\n------------------------------\n\nStart the Cloud SQL Auth Proxy in its own terminal so you can monitor its output. Replace\n`INSTANCE_CONNECTION_NAME` with the instance connection name you copied\nin the previous step.\n\nFor Linux environments, use this command to launch the Cloud SQL Auth Proxy: \n\n```bash\n./cloud-sql-proxy INSTANCE_CONNECTION_NAME\n```\n\n\u003cbr /\u003e\n\nIn PowerShell on Windows, use this command to launch the Cloud SQL Auth Proxy: \n\n```bash\n.\\cloud-sql-proxy.exe INSTANCE_CONNECTION_NAME\n```\n\n\u003cbr /\u003e\n\nA message similar to the following appears: \n\n```\nListening on 127.0.0.1:1433 for INSTANCE_CONNECTION_NAME\nReady for new connections\n```\n\nRun the following command, replacing `USER_NAME` with your SQL Server username.\n\n\u003cbr /\u003e\n\n```bash\nsqlcmd -S 127.0.0.1 -U USER_NAME\n```\n\nReturn to the terminal window where you started the Cloud SQL Auth Proxy. You\nshould see a message similar to the following:\n\n`New connection for `*myInstance*\n\nClean up\n--------\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, follow these steps.\n\n1. In the Google Cloud console, go to the **Cloud SQL Instances** page.\n\n [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)\n2. Select the `myinstance` instance to open the **Instance details** page.\n3. In the icon bar at the top of the page, click **Delete**.\n4. In the **Delete instance** window, type your instance's name and then click **Delete**.\n\n### Optional cleanup steps\n\nIf you're not using the APIs that were enabled as part of this quickstart, you\ncan disable them.\n\n- APIs that were enabled within this quickstart:\n - Cloud SQL Admin API\n\n1.\n\n In the Google Cloud console, go to the **APIs** page.\n\n [Go to APIs](https://console.cloud.google.com/apis)\n\n \u003cbr /\u003e\n\n2. Select the Cloud SQL Admin API and then click the\n **Disable API** button.\n\nWhat's next\n-----------\n\n- See how to [troubleshoot information for the Cloud SQL Auth Proxy](/sql/docs/sqlserver/connect-auth-proxy#troubleshooting).\n\n- Learn more [about the Cloud SQL Auth Proxy](/sql/docs/sqlserver/sql-proxy)."]]