Learn how to deploy a sample app on your Linux or Windows based Compute Engine VM instance connected to a SQL Server instance by using the Google Cloud console and a client application.
Assuming that you complete all the steps in a timely manner, the resources created in this quickstart typically cost less than one dollar (USD).
Before you begin 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.In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
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.Verify that billing is enabled for your Google Cloud project.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
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.Verify that billing is enabled for your Google Cloud project.
Click the Enable APIs button to enable the API required for this quickstart.
This enables the following API:
Install the gcloud CLI which provides command-line access to your Google Cloud resources. The gcloud CLI is used to run the gcloud CLI
commands presented throughout this quickstart. All the commands are formatted to be run in a terminal or a Powershell window.
Run the following gcloud
command:
gcloud services enable sqladmin.googleapis.com
This command enables the following API:
In the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance
.Before running the gcloud sql instances create
command as follows, replace DB_ROOT_PASSWORD with the password of your database user.
Optionally, modify the values for the following parameters:
us-central
is used. See the full list of regions.Run the gcloud sql instances create
command to create a Cloud SQL instance.
gcloud sql instances create quickstart-instance --database-version=SQLSERVER_2019_STANDARD --cpu=1 --memory=4GB --region=us-central --root-password=DB_ROOT_PASSWORDPrivate IP Console Allocate an IP address range and create a private connection to configure private services access for Cloud SQL
In the Google Cloud console, go to the VPC networks page.
default
VPC network.google-managed-services-default
.16
.default
VPC network.google-managed-services-default
.In the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance
for Instance ID.Run the gcloud compute addresses create
command to allocate an IP address range.
gcloud compute addresses create google-managed-services-default --global --purpose=VPC_PEERING --prefix-length=16 --description="peering range for Google" --network=default
Run the gcloud services vpc-peerings connect
command to create a private connection to the allocated IP address range. Replace YOUR_PROJECT_ID with your project's project ID.
gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com --ranges=google-managed-services-default --network=default --project=YOUR_PROJECT_ID
Before running the command as follows, replace DB_ROOT_PASSWORD with the password of your database user.
Optionally, modify the values for the following parameters:
us-central1
is used. See the full list of regions.Run the gcloud sql instances create
command to create a Cloud SQL instance with a Private IP address.
gcloud beta sql instances create quickstart-instance --database-version=SQLSERVER_2017_STANDARD --cpu=1 --memory=4GB --region=us-central --root-password=DB_ROOT_PASSWORD --no-assign-ip --network=default
Run the gcloud sql instances patch
command to enable only allow SSL connections for the instance.
gcloud sql instances patch quickstart-instance --require-ssl
In the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance
.quickstart_db
as the name of the database.Run the gcloud sql databases create
command to create a database.
gcloud sql databases create quickstart_db --instance=quickstart-instanceConfigure a Compute Engine service account
Create and configure a Google Cloud service account that has the
Cloud SQL Clientrole with permissions to connect to Cloud SQL. After you create a service account, you might need to wait for 60 seconds or more before you use the service account.
Console Create a service accountquickstart-service-account
as the service account name.gcloud iam service-accounts create
command:gcloud iam service-accounts create quickstart-service-account --description="DESCRIPTION" --display-name="quickstart-service-account"
Replace the following value:
DESCRIPTION
: an optional description of the service accountgcloud projects add-iam-policy-binding
command. Replace PROJECT_ID with your Google Cloud project ID:
gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:quickstart-service-account@PROJECT_ID.iam.gserviceaccount.com" --role="roles/cloudsql.client" --role="roles/storage.objectViewer"
Create a Compute Engine VM Instance to host a sample web app that connects to Cloud SQL.
Create a Linux VM Instance ConsoleIn the Google Cloud console, go to the VM instances page.
quickstart-vm-instance
.quickstart-service-account
.Before running the following command, replace YOUR_PROJECT_ID with your project ID.
Run the following gcloud compute instances create
command.
gcloud compute instances create quickstart-vm-instance --image-family=debian-10 --image-project=debian-cloud --machine-type=e2-medium --service-account=quickstart-service-account@YOUR_PROJECT_ID.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/cloud-platform --tags=http-server --zone=us-central1-aCreate a Windows VM Instance Console
In the Google Cloud console, go to the VM instances page.
quickstart-vm-instance
.quickstart-service-account
.Before running the following command, replace YOUR_PROJECT_ID with your project ID.
Run the following gcloud compute instances create
command in a Terminal Window.
gcloud compute instances create quickstart-vm-instance --image-project=windows-cloud --image-family=windows-2022 --machine-type=e2-medium --service-account=quickstart-service-account@YOUR_PROJECT_ID.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/cloud-platform --tags=http-server --zone=us-central1-a
After 2-3 minutes once the VM instance has started, run the following command to set the Windows password on the VM instance.
gcloud compute reset-windows-password quickstart-vm-instance
Copy and save this password in a secure location as you will be using it to access your VM instance in the next step of this quickstart.
Access Compute Engine VM instance Access Linux VM Instance ConsoleNote: When you connect to VMs using the Google Cloud console, Compute Engine creates an ephemeral SSH key for you. For more information about SSH keys, see SSH connections to Linux VMs
gcloudUse the gcloud compute ssh
command to connect to a Linux VM instance. Replace YOUR_PROJECT_ID with your project ID:
gcloud compute ssh --project=YOUR_PROJECT_ID --zone=us-central1-a quickstart-vm-instanceAccess Windows VM Instance Chrome RDP plugin
Chrome RDP for Google Cloud is a third-party plugin that lets you connect to Windows instances by using the Chrome browser. The plugin is integrated with the Google Cloud console. After you install the plugin, connect to any Windows Server instance by using the RDP button in the Google Cloud console.
To connect using the Chrome RDP plugin, do the following:
See Connect to Windows VMs using RDP for more options for accessing a Compute Engine Windows VM instance.
Setup development environment for programming languageSet up the Compute Engine VM instance's development environment for your preferred programming language.
Setup Linux VM Instance development environment GoComplete the following steps to set up the Compute Engine VM instance's development environment to run the Go sample app.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Java sample app.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Node.js sample app.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Python sample app.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Go sample app.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Java sample app.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Node.js sample app.
Complete the following steps to set up the Compute Engine VM instance's development environment to run the Python sample app.
pip install
command.pip install virtualenv
Install Git, an open source version control system on to your Compute Engine VM instance.
Compute Engine Linux VM instanceOn your Compute Engine Linux VM instance, follow the official Git installation documentation for Linux.
install git
command using the sudo
command prefix to run the command as an administrator. The full installation command to run in the terminal should be formatted as follows:sudo apt-get install gitCompute Engine Windows VM instance
On your Compute Engine Windows VM instance, follow the official Git installation documentation for Windows to download the 64-bit Standalone Installer and run it to install Git.
Clone sample appClone a sample app to your Compute Engine VM instance using the git clone
command.
On your Compute Engine VM instance, open a new terminal or Powershell window. Run the following commands to clone the Go sample app and change the directory to the directory containing the sample app.
git clone https://github.com/GoogleCloudPlatform/golang-samples
cd golang-samples/cloudsql/sqlserver/database-sql
On your Compute Engine VM instance, open a new terminal or Powershell window. Run the following commands to clone the Java sample app and change the directory to the directory containing the sample app.
git clone https://github.com/GoogleCloudPlatform/java-docs-samples
cd java-docs-samples/cloud-sql/sqlserver/servlet
On your Compute Engine VM instance, open a new terminal or Powershell window. Run the following commands to clone the Node.js sample app and change the directory to the directory containing the sample app.
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
cd nodejs-docs-samples/cloud-sql/sqlserver/mssql
On your Compute Engine VM instance, open a new terminal or Powershell window. Run the following commands to clone the Python sample app and change the directory to the directory containing the sample app.
git clone https://github.com/GoogleCloudPlatform/python-docs-samples
cd python-docs-samples/cloud-sql/sql-server/sqlalchemy
With a Cloud SQL instance, database, and service account with client permissions, you can now configure a sample application running on your Compute Engine VM instance to connect to your Cloud SQL instance.
Public IP Cloud SQL Instance and Linux based Compute Engine VM GoOn the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME' export DB_PORT='1433' export DB_NAME='quickstart_db' export DB_USER='sqlserver' export DB_PASS='YOUR_DB_PASSWORD'
On the Compute Engine VM instance in the open terminal, run the following commands to get the Go sample app's dependencies on to your Compute Engine VM instance and run the sample app.
go get ./...
go run cmd/app/main.go
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
Note: This quickstart step requires the gcloud CLI, which provides command-line access to your Google Cloud resources usinggcloud CLI
commands. If you don't have the gcloud CLI installed on your local computer, then install the gcloud CLI to proceed.
gcloud compute instances describe
command:gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
JavaOn the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME' export DB_PORT='1433' export DB_NAME='quickstart_db' export DB_USER='sqlserver' export DB_PASS='YOUR_DB_PASSWORD'
On the Compute Engine VM instance in the open terminal, run the following command to get the Java sample app's dependencies on to your Compute Engine VM instance and run the sample app.
mvn jetty:run
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
Note: This quickstart step requires the gcloud CLI, which provides command-line access to your Google Cloud resources usinggcloud CLI
commands. If you don't have the gcloud CLI installed on your local computer, then install the gcloud CLI to proceed.
gcloud compute instances describe
command:gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Node.jsOn the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacement:
quickstart-user
that you created in the previous Create a user quickstart step.export INSTANCE_HOST='127.0.0.1' export DB_PORT='1433' export DB_NAME='quickstart_db' export DB_USER='sqlserver' export DB_PASS='YOUR_DB_PASSWORD'
curl -o cloud-sql-proxy \ https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.0.0/cloud-sql-proxy.linux.amd64
chmod +x cloud-sql-proxy
./cloud-sql-proxy INSTANCE_CONNECTION_NAME &
fg
command in your Terminal window where you started the sample app. This should bring the running Cloud SQL Auth Proxy job to the terminal foreground. Then press the Ctrl + C keys to stop the proxy job.
On the Compute Engine VM instance in the open terminal, run the following commands to get the required Node.js packages on to your Compute Engine VM instance and run the sample app.
npm install
npm start
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
Note: This quickstart step requires the gcloud CLI, which provides command-line access to your Google Cloud resources usinggcloud CLI
commands. If you don't have the gcloud CLI installed on your local computer, then install the gcloud CLI to proceed.
gcloud compute instances describe
command:gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
PythonOn the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME' export DB_PORT='1433' export DB_NAME='quickstart_db' export DB_USER='sqlserver' export DB_PASS='YOUR_DB_PASSWORD'
On the Compute Engine VM instance in the open terminal, run the following commands to get the Python sample app's requirements on to your Compute Engine VM instance and run the sample app.
python3 -m venv env source env/bin/activate pip install -r requirements.txt
python app.py
On your local computer, set up port forwarding over SSH by performing the instructions in next quickstart step. This enables you to use a browser on your local computer to view the app running on your Compute Engine VM instance.
Note: This quickstart step requires the gcloud CLI, which provides command-line access to your Google Cloud resources usinggcloud CLI
commands. If you don't have the gcloud CLI installed on your local computer, then install the gcloud CLI to proceed.
gcloud compute ssh
command to setup port forwarding over SSH. Before running the command, replace YOUR_PROJECT_ID with your project ID.gcloud compute ssh quickstart-vm-instance --project=YOUR_PROJECT_ID --zone=us-central1-a --ssh-flag='-L 8000:127.0.0.1:8080'
http://127.0.0.1:8000
in the address bar of your browser..
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Public IP Cloud SQL Instance and Windows based Compute Engine VM GoOn the Compute Engine VM instance in the open Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME" $env:DB_PORT="1433" $env:DB_NAME="quickstart_db" $env:DB_USER="sqlserver" $env:DB_PASS="YOUR_DB_PASSWORD"
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the Go sample app's dependencies on to your Compute Engine VM instance and run the sample app.
go get ./...
go run cmd\app\main.go
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
JavaOn the Compute Engine VM instance in the open Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME" $env:DB_PORT="1433" $env:DB_NAME="quickstart_db" $env:DB_USER="sqlserver" $env:DB_PASS="YOUR_DB_PASSWORD"
On the Compute Engine VM instance in the open Powershell window, run the following command to get the Java sample app's dependencies on to your Compute Engine VM instance and run the sample app.
mvn jetty:run
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Node.jsOn the Compute Engine VM instance in the open Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacement:
quickstart-user
that you created in the previous Create a user quickstart step.$env:INSTANCE_HOST="127.0.0.1" $env:DB_PORT="1433" $env:DB_NAME="quickstart_db" $env:DB_USER="sqlserver" $env:DB_PASS="YOUR_DB_PASSWORD"
wget https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.0.0/cloud-sql-proxy.x64.exe ` -O cloud-sql-proxy.exe
Start-Process -filepath ".\cloud-sql-proxy.exe" -ArgumentList ` "INSTANCE_CONNECTION_NAME"
Start-Process
command. Then close the window to stop the proxy job.
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the required Node.js packages on to your Compute Engine VM instance and run the sample app.
npm install
npm start
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
PythonOn the Compute Engine VM instance in the open Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME" $env:DB_PORT="1433" $env:DB_NAME="quickstart_db" $env:DB_USER="sqlserver" $env:DB_PASS="YOUR_DB_PASSWORD"
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the Python sample app's requirements on to your Compute Engine VM instance and run the sample app.
virtualenv --python python3 env .\env\Scripts\activate pip install -r requirements.txt
python app.py
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Private IP Cloud SQL Instance and Linux based Compute Engine VM Create and download SSL server certificate on to your local computerIn the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance
to see its Overview page.In a browser on your local computer, create a Cloud Storage bucket and upload the SSL certificate to the bucket where it can then be accessed from the Compute Engine VM instance.
YOUR_PROJECT_ID-quickstart-certs
server-ca.pem
On your local computer in a terminal or Powershell window open to the directory where you downloaded the SSL certificate, you can now create a Cloud Storage bucket and upload the SSL certificate to bucket where it can then be accessed from the Compute Engine VM instance. The gcloud CLI will be used to upload the file.
gcloud storage buckts create
command to make a new Cloud Storage bucket:gcloud storage buckets create gs://YOUR_PROJECT_ID-quickstart-certs --location=us-central1
gcloud storage cp
command to copy the SSL certificates to the newly created Cloud Storage bucket:gcloud storage cp server-ca.pem gs://YOUR_PROJECT_ID-quickstart-certs/
On the Compute Engine VM instance in a terminal open to the golang-samples/cloudsql/sqlserver/database-sql
directory, run the following gcloud storage cp
command to download the SSL certificates from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.export INSTANCE_HOST='INSTANCE_HOST' export DB_PORT='1433' export DB_NAME='quickstart_db' export DB_USER='sqlserver' export DB_PASS='YOUR_DB_PASSWORD' export DB_ROOT_CERT='certs/server-ca.pem' export PRIVATE_IP='TRUE'
On the Compute Engine VM instance in the open terminal, run the following commands to get the Go sample app's dependencies on to your Compute Engine VM instance and run the sample app.
go get ./...
go run cmd/app/main.go
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
Note: This quickstart step requires the gcloud CLI, which provides command-line access to your Google Cloud resources usinggcloud CLI
commands. If you don't have the gcloud CLI installed on your local computer, then install the gcloud CLI to proceed.
gcloud compute instances describe
command:gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Java Download SSL certificate using the gcloud CLI on the Compute Engine VM instanceOn the Compute Engine VM instance in a terminal open to the java-docs-samples/cloud-sql/sqlserver/servlet/
directory, run the following gcloud storage cp
command to download the SSL certificates from Cloud Storage to the current directory.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem .Configure the SSL certificates for use in Java on the Compute Engine VM instance
In the terminal on the Compute Engine VM instance, run the following command to import the server certificate into a custom Java truststore using keytool. Before running the following command, replace TRUST_CERT_KEYSTORE_PASSWD with your own custom keystore password to be used to create the Java truststore.
keytool -importcert -alias MySQLCACert -file server-ca.pem \ -keystore quickstart-truststore -storepass TRUST_CERT_KEYSTORE_PASSWDSet Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.export INSTANCE_HOST='INSTANCE_HOST' export DB_PORT='1433' export DB_NAME='quickstart_db' export DB_USER='sqlserver' export DB_PASS='YOUR_DB_PASSWORD' export TRUST_CERT_KEYSTORE_PATH='quickstart-truststore' export TRUST_CERT_KEYSTORE_PASSWD='TRUST_CERT_KEYSTORE_PASSWD' export PRIVATE_IP='TRUE'
On the Compute Engine VM instance in the open terminal, run the following command to get the Java sample app's dependencies on to your Compute Engine VM instance and run the sample app.
mvn jetty:run
On your local computer get the Compute Engine VM instance's external IP address where the sample app is running and view it in a browser.
Note: This quickstart step requires the gcloud CLI, which provides command-line access to your Google Cloud resources usinggcloud CLI
commands. If you don't have the gcloud CLI installed on your local computer, then install the gcloud CLI to proceed.
gcloud compute instances describe
command:gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Python Download SSL certificate using the gcloud CLI on the Compute Engine VM instanceOn the Compute Engine VM instance in a terminal open to the python-docs-samples/cloud-sql/sql-server/sqlalchemy
directory, run the following gcloud storage cp
command to download the SSL certificates from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the open terminal, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.export INSTANCE_HOST='INSTANCE_HOST' export DB_PORT='1433' export DB_NAME='quickstart_db' export DB_USER='sqlserver' export DB_PASS='YOUR_DB_PASSWORD' export DB_ROOT_CERT='certs/server-ca.pem' export PRIVATE_IP='TRUE'
On the Compute Engine VM instance in the open terminal, run the following commands to get the Python sample app's requirements on to your Compute Engine VM instance and run the sample app.
python3 -m venv env source env/bin/activate pip install -r requirements.txt
python app.py
On your local computer, set up port forwarding over SSH by performing the instructions in next quickstart step. This enables you to use a browser on your local computer to view the app running on your Compute Engine VM instance.
Note: This quickstart step requires the gcloud CLI, which provides command-line access to your Google Cloud resources usinggcloud CLI
commands. If you don't have the gcloud CLI installed on your local computer, then install the gcloud CLI to proceed.
gcloud compute ssh
command to setup port forwarding over SSH. Before running the command, replace YOUR_PROJECT_ID with your project ID.gcloud compute ssh quickstart-vm-instance --project=YOUR_PROJECT_ID --zone=us-central1-a --ssh-flag='-L 8000:127.0.0.1:8080'
http://127.0.0.1:8000
in the address bar of your browser..
To stop the sample app, press Control+C in the Compute Engine VM instance terminal where you started the sample app.
Private IP Cloud SQL Instance and Windows based Compute Engine VM Create and download SSL server certificate on to your local computerIn the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance
to see its Overview page.In a browser on your local computer, create a Cloud Storage bucket and upload the SSL certificate to the bucket where it can then be accessed from the Compute Engine VM instance.
YOUR_PROJECT_ID-quickstart-certs
server-ca.pem
On your local computer in a terminal or Powershell window open to the directory where you downloaded the SSL certificate, you can now create a Cloud Storage bucket and upload the SSL certificate to bucket where it can then be accessed from the Compute Engine VM instance. The gcloud CLI will be used to upload the file.
gcloud storage buckts create
command to make a new Cloud Storage bucket:gcloud storage buckets create gs://YOUR_PROJECT_ID-quickstart-certs --location=us-central1
gcloud storage cp
command to copy the SSL certificates to the newly created Cloud Storage bucket:gcloud storage cp server-ca.pem gs://YOUR_PROJECT_ID-quickstart-certs/
On the Compute Engine VM instance in a Powershell window open to the golang-samples/cloudsql/sqlserver/database-sql
directory, run the following gcloud storage cp
command to download the SSL certificate from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.$env:INSTANCE_HOST="INSTANCE_HOST" $env:DB_PORT="1433" $env:DB_NAME="quickstart_db" $env:DB_USER="sqlserver" $env:DB_PASS="YOUR_DB_PASSWORD" $env:DB_ROOT_CERT="certs/server-ca.pem" $env:PRIVATE_IP="TRUE"
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the Go sample app's dependencies on to your Compute Engine VM instance and run the sample app.
go get ./...
go run cmd\app\main.go
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Java Download SSL certificate using the gcloud CLI on the Compute Engine VM instanceOn the Compute Engine VM instance in a Powershell window open to the java-docs-samples/cloud-sql/sqlserver/servlet/
directory, run the following gcloud storage cp
command to download the SSL certificate from Cloud Storage to the current directory.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem .Configure the SSL certificates for use in Java on the Compute Engine VM instance
In the terminal on the Compute Engine VM instance, run the following command to import the server certificate into a custom Java truststore using keytool. Before running the following command, replace TRUST_CERT_KEYSTORE_PASSWD with your own custom keystore password to be used to create the Java truststore.
keytool -importcert -alias SQLServerCACert -file server-ca.pem ` -keystore quickstart-truststore -storepass TRUST_CERT_KEYSTORE_PASSWDSet Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.--storepass
in the previous step.$env:INSTANCE_HOST="INSTANCE_HOST" $env:DB_PORT="1433" $env:DB_NAME="quickstart_db" $env:DB_USER="sqlserver" $env:DB_PASS="YOUR_DB_PASSWORD" $env:TRUST_CERT_KEYSTORE_PATH="quickstart-truststore" $env:TRUST_CERT_KEYSTORE_PASSWD="TRUST_CERT_KEYSTORE_PASSWD" $env:PRIVATE_IP="TRUE"
On the Compute Engine VM instance in the open Powershell window, run the following command to get the Java sample app's dependencies on to your Compute Engine VM instance and run the sample app.
mvn jetty:run
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Python Download SSL certificate using the gcloud CLI on the Compute Engine VM instanceOn the Compute Engine VM instance in a Powershell window open to the python-docs-samples/cloud-sql/sql-server/sqlalchemy
directory, run the following gcloud storage cp
command to download the SSL certificate from Cloud Storage to the certs
directory.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.Set Environment Variables on the Compute Engine VM instance
On the Compute Engine VM instance in the Powershell window, run the following commands to initialize environment variables required to run the sample app. Before running the commands, make the following replacements:
quickstart-user
that you created in the previous Create a user quickstart step.$env:INSTANCE_HOST="INSTANCE_HOST" $env:DB_PORT="1433" $env:DB_NAME="quickstart_db" $env:DB_USER="sqlserver" $env:DB_PASS="YOUR_DB_PASSWORD" $env:DB_ROOT_CERT="certs/server-ca.pem" $env:PRIVATE_IP="TRUE"
On the Compute Engine VM instance in the open Powershell window, run the following commands to get the Python sample app's requirements on to your Compute Engine VM instance and run the sample app.
virtualenv --python python3 env .\env\Scripts\activate pip install -r requirements.txt
python app.py
http://127.0.0.1:8080
.
To stop the sample app, press Control+C in the Compute Engine VM instance Powershell window where you started the sample app.
Clean upTo avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
Delete Cloud SQL instanceIn the Google Cloud console, go to the Cloud SQL Instances page.
quickstart-instance
instance to open the Instance details page.quickstart-instance
, and then click Delete to delete the instance.In the Google Cloud console, go to the VM instances page.
quickstart-vm-instance
instance to open the Instance details page.If you're not using the Cloud SQL client role that you assigned to the Compute Engine default
service account, you can remove it.
In the Google Cloud console, go to the IAM page.
If you're not using the API that was enabled as part of this quickstart, you can disable it.
In the Google Cloud console, go to the APIs page.
Select any API that you would like to disable and then click the Disable API button.
You also can learn about creating SQL Server users and databases for your Cloud SQL instance.
For more information about pricing, see Cloud SQL for SQL Server pricing.
Learn more about:
Additionally, you can learn about connecting to a Cloud SQL instance from other Google Cloud applications:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4