Cette page vous explique comment vous connecter à Cloud SQL depuis un environnement de test local à l'aide du proxy d'authentification Cloud SQL. Le proxy d'authentification Cloud SQL fournit un accès sécurisé à votre instance Cloud SQL, sans nécessiter de réseaux autorisés ni de configuration SSL. Vous pouvez vous connecter en toute sécurité à votre instance Cloud SQL à l'aide de ce proxy.
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.
Cliquez sur le bouton suivant pour ouvrir Cloud Shell, qui fournit un accès en ligne de commande à vos ressources Google Cloud directement depuis le navigateur.
Cloud Shell peut être utilisé pour exécuter les commandes gcloud présentées dans ce guide de démarrage rapide.
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.
Dans le champ Nouveaux comptes principaux, saisissez votre identifiant utilisateur.
Il s'agit généralement de l'adresse e-mail d'un compte Google.
Dans la liste Sélectionner un rôle, sélectionnez un rôle.
Pour attribuer des rôles supplémentaires, cliquez sur addAjouter un autre rôle et ajoutez tous les rôles supplémentaires.
Cliquez sur Enregistrer.
Créer une instance Cloud SQL
Dans ce guide de démarrage rapide, vous allez utiliser la console Google Cloud . Pour utiliser la gcloud CLI, cURL ou PowerShell, consultez la section Créer des instances.
Dans la console Google Cloud , accédez à la page Instances Cloud SQL.
Dans le champ ID d'instance, saisissez myinstance.
Dans le champ Mot de passe, entrez le mot de passe de l'utilisateur sqlserver.
Cliquez sur Créer une instance.
Vous êtes redirigé vers la liste des instances. Vous pouvez cliquer directement sur la nouvelle instance pour en afficher les détails, mais elle ne sera disponible pour les autres opérations qu'une fois initialisée et démarrée.
Debian/Ubuntu
Pour Debian/Ubuntu, installez les outils de ligne de commande SQL Server applicables en suivant ces instructions.
CentOS/RHEL
Pour CentOS/RHEL, installez les outils de ligne de commande SQL Server applicables en suivant ces instructions.
openSUSE
Pour openSUSE, installez les outils de ligne de commande SQL Server applicables en suivant ces instructions.
Cliquez sur le nom de l'instance pour ouvrir la page Présentation.
Dans la section Se connecter à cette instance, copiez le nom de la connexion. Le nom de la connexion est au format projectID:region:instanceID.
Démarrer le proxy d'authentification Cloud SQL
Démarrez le proxy d'authentification Cloud SQL dans son propre terminal afin de pouvoir surveiller sa sortie. Remplacez INSTANCE_CONNECTION_NAME par le nom de connexion de l'instance que vous avez copié à l'étape précédente.
Pour les environnements Linux, lancez le proxy d'authentification Cloud SQL à l'aide de la commande suivante :
./cloud-sql-proxyINSTANCE_CONNECTION_NAME
Dans PowerShell sous Windows, lancez le proxy d'authentification Cloud SQL à l'aide de la commande suivante :
.\cloud-sql-proxy.exeINSTANCE_CONNECTION_NAME
Un message de ce type s'affiche :
Listening on 127.0.0.1:1433 for INSTANCE_CONNECTION_NAME
Ready for new connections
Exécutez la commande suivante en remplaçant USER_NAME par votre nom d'utilisateur SQL Server.
sqlcmd-S127.0.0.1-UUSER_NAME
Revenez à la fenêtre de terminal dans laquelle vous avez démarré le proxy d'authentification Cloud SQL. Un message semblable au suivant doit s'afficher :
New connection for myInstance
Effectuer un nettoyage
Pour éviter que les ressources utilisées dans cette démonstration soient facturées sur votre compte Google Cloud , procédez comme suit :
Dans la console Google Cloud , accédez à la page Instances Cloud SQL.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)."]]