En esta página, se muestra cómo conectarse a Cloud SQL desde un entorno de prueba local con el proxy de Cloud SQL Auth. El proxy de Cloud SQL Auth proporciona acceso seguro a tu instancia de Cloud SQL sin la necesidad de contar con redes autorizadas ni de configurar SSL. Mediante el proxy de Cloud SQL Aurh, puedes conectarte a tu instancia de Cloud SQL de forma segura.
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.
Haz clic en el siguiente botón para abrir Cloud Shell, que proporciona
acceso de línea de comandos a tus recursos de Google Cloud directamente desde el navegador.
Cloud Shell se puede usar para ejecutar los comandos de gcloud que se presentan en esta guía de inicio rápido.
Ejecuta el comando gcloud services enable de la siguiente manera con Cloud Shell a fin de habilitar las API necesarias para esta guía de inicio rápido:
gcloudservicesenablesqladmin.googleapis.com
Este comando habilita las siguientes API:
API de Cloud SQL Admin
Make sure that you have the following role or roles on the project:
Cloud SQL Admin (roles/cloudsql.admin), Cloud SQL Viewer (roles/cloudsql.viewer)
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.
En el campo Principales nuevas, ingresa tu identificador de usuario.
Esta suele ser la dirección de correo electrónico de una Cuenta de Google.
En la lista Seleccionar un rol, elige uno.
Para otorgar roles adicionales, haz clic en addAgregar
otro rol y agrega uno más.
Haz clic en Guardar.
Cree una instancia de Cloud SQL
En esta guía de inicio rápido, usarás la Google Cloud consola. Para usar
gcloud CLI, cURL o PowerShell, consulta la documentación sobre
cómo crear instancias.
En la Google Cloud consola, ve a la página Instancias de Cloud SQL.
En el campo Contraseña, ingresa una contraseña para el usuario sqlserver.
Haz clic en Crear instancia.
Volverás a la lista de las instancias. Puedes hacer clic en la instancia nueva de inmediato para ver los detalles, pero no estará disponible para otras operaciones hasta que se inicialice y se inicie.
Debian/Ubuntu
En Debian/Ubuntu, instala las herramientas de línea de comandos de SQL Server aplicables mediante estas instrucciones.
CentOS/RHEL
Para CentOS/RHEL, instala las herramientas de línea de comandos de SQL Server aplicables mediante estas instrucciones.
openSUSE
Para openSUSE, instala las herramientas de línea de comandos de SQL Server aplicables mediante estas instrucciones.
Haz clic en el nombre de la instancia para abrir la página Descripción general de esa instancia.
En la sección Conéctate a esta instancia, copia el Nombre de la conexión. El nombre de la conexión tiene el formato projectID:region:instanceID.
Inicia el proxy de Cloud SQL Auth
Inicia el proxy de Cloud SQL Auth en su propia terminal para poder supervisar el resultado. Reemplaza INSTANCE_CONNECTION_NAME por el nombre de la conexión de instancia que copiaste en el paso anterior.
En entornos de Linux, usa este comando para iniciar el proxy de Cloud SQL Auth:
./cloud-sql-proxyINSTANCE_CONNECTION_NAME
En PowerShell de Windows, usa este comando para iniciar el proxy de Cloud SQL Auth:
.\cloud-sql-proxy.exeINSTANCE_CONNECTION_NAME
Aparecerá un mensaje similar al que figura a continuación:
Listening on 127.0.0.1:1433 for INSTANCE_CONNECTION_NAME
Ready for new connections
Ejecuta el siguiente comando y reemplaza USER_NAME por tu nombre de usuario de SQL Server.
sqlcmd-S127.0.0.1-UUSER_NAME
Regresa a la ventana de terminal en la que iniciaste el proxy de Cloud SQL Auth. Deberías ver un mensaje similar al siguiente:
New connection for myInstance
Limpia
Sigue estos pasos para evitar que se apliquen cargos a tu cuenta de Google Cloud por los recursos que usaste en esta página.
En la Google Cloud consola, ve a la página Instancias de Cloud SQL.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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)."]]