Learn how to deploy a sample app on your Linux or Windows based Compute Engine VM instance
connected to a MySQL 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
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.
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:
gcloudservicesenablesqladmin.googleapis.com
This command enables the following API:
Cloud SQL Admin API
Set up Cloud SQL
Create a Cloud SQL instance
Public IP
Console
Create an instance with a public IP address
In the Google Cloud console, go to the Cloud SQL Instances page.
In the Instance ID field, enter
quickstart-instance.
In the Password field, enter a password for
the root user. Save this password for future use.
In the Choose region and zonal availability
section, select Single zone.
Expand the Show Configurations section.
In the Machine Type drop-down list, select Lightweight.
Click Create Instance and then wait
until the instance initializes and starts.
gcloud
Create an instance with a public IP address
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:
--database_version: The database engine type and version.
If left unspecified, the API default is used.
See the gcloud database versions
documentation to see the currently available versions.
--cpu: The number of cores
desired in the machine.
--memory: Whole number value indicating how
much memory is desired in the machine. A size unit should be
provided (for example, 3072MB or 9GB). If no units are specified,
GB is assumed.
--region: Regional location of the instance
(for example asia-east1, us-east1). If left unspecified, the default
us-central is used.
See the full list of regions.
gcloudcomputeaddressescreategoogle-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.
Create an instance with private IP address and SSL enabled
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:
--database_version: The database engine type and version.
If left unspecified, the API default is used.
See the gcloud database versions
documentation to see the currently available versions.
--cpu: The number of cores in the machine.
--memory: A whole number value indicating how
much memory to include in the machine. A size unit can be
provided (for example, 3072MB or 9GB). If no units are specified,
GB is assumed.
--region: The regional location of the instance
(for example asia-east1, us-east1). If left unspecified, the default
us-central1 is used.
See the full list of regions.
To open the Overview page of an instance, click the instance name.
Select Users from the SQL navigation menu.
Click Add user account.
In the Add a user account to instance instance_name page,
add the following information:
Username: Set to quickstart-user
Password: Specify a password for your database user.
Make a note of this for use in a later step of this quickstart.
In the Host name section, the default is Allow any host,
which means that the user can connect from any IP address.
Optionally, select Restrict host by IP address or address range
and enter an IP address or address range in the Host section.
The user can then connect only from the IP address or
addresses specified.
Click Add.
gcloud
Before running the following command, make the following replacements:
PASSWORD with a password for your database user.
Make a note of this for use in a later step of this quickstart.
User name length limits are the same for Cloud SQL as for
on-premises MySQL; 32 characters for MySQL 8.0 and later, 16 characters for
earlier versions.
Configure a Compute Engine service account
Create and configure a Google Cloud service account that has the
Cloud SQL Client role 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 account
In the Google Cloud console, go to the Create service account page.
DESCRIPTION: an optional description of the
service account
To grant your service account the Cloud SQL Client role
and the Storage Object Viewer role on your project, run the
gcloud projects add-iam-policy-binding
command. Replace PROJECT_ID with your Google Cloud project ID:
In the list of virtual machine instances, click SSH in the row of
the instance that you want to connect to.
Note: 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
gcloud
Use the
gcloud compute ssh command to connect
to a Linux VM instance. Replace YOUR_PROJECT_ID with your project ID:
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:
Complete the instructions in the Installing Python section.
The instructions above will have you visit the Python Releases
for Windows download page. From that page click the
Latest Python 3 Release link.
On the Python 3.X.X page, click the Windows Installer 64-bit
link to download the installer file to your
Windows Compute Engine VM instance.
Once you've downloaded the Python installer to the VM instance,
open the folder containing the downloaded file. Then right click
on the installer file and select Run as administrator.
In the Install Python dialog that appears, select the
option to Add Python 3.X.X to PATH and click → Install Now.
Use PIP to install virtualenv.
Open Powershell on the Windows Compute Engine VM instance and
run the following pip install command.
pipinstallvirtualenv
Install Git
Install Git, an open source version control system
on to your Compute Engine VM instance.
Run the suggested Debian/Ubuntuinstall 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 git
Compute 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 app
Clone a sample app to your Compute Engine VM instance using the git clone command.
Go
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.
Change directory to the directory containing the sample app.
cdgolang-samples/cloudsql/mysql/database-sql
Java
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.
Change directory to the directory containing the sample app.
cdjava-docs-samples/cloud-sql/mysql/servlet
Node.js
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.
Change directory to the directory containing the sample app.
cdnodejs-docs-samples/cloud-sql/mysql/mysql
Python
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.
Change directory to the directory containing the sample app.
cdpython-docs-samples/cloud-sql/mysql/sqlalchemy
Configure and run a Cloud SQL sample app
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
Go
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:
INSTANCE_CONNECTION_NAME with your instance's Connection name that appears
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created
in the previous Create a user quickstart step.
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.
Get the dependencies required to run to sample app.
goget./...
Run the sample app.
goruncmd/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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following gcloud compute instances describe command:
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
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
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:
INSTANCE_CONNECTION_NAME with your instance's Connection name that appears
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created
in the previous Create a user quickstart step.
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.
mvnjetty: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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following gcloud compute instances describe command:
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
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.js
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 replacement:
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the previous Create a user quickstart step.
Set permissions to make the Cloud SQL Auth Proxy file executable.
chmod+xcloud-sql-proxy
Run the Cloud SQL Auth Proxy as a background process. Replace INSTANCE_CONNECTION_NAME with your
instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
./cloud-sql-proxyINSTANCE_CONNECTION_NAME&
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.
Install the Node.js packages necessary to run the app locally.
npminstall
Run the sample app.
npmstart
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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following gcloud compute instances describe command:
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
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
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:
INSTANCE_CONNECTION_NAME with your instance's Connection name that appears
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created
in the previous Create a user quickstart step.
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.
Initialize a virtual environment and install the requirements to run to sample app.
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.
In a terminal or in Powershell on your local computer, run the following
gcloud compute ssh
command to setup port forwarding over SSH. Before running the command,
replace YOUR_PROJECT_ID with your project ID.
View the running sample app. With port forwarding actively running,
open a browser on your local computer and enter 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
Go
On 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:
INSTANCE_CONNECTION_NAME with your instance's Connection name that appears
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created
in the previous Create a user quickstart step.
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.
Get the dependencies required to run to sample app.
goget./...
Run the sample app.
goruncmd\app\main.go
View the running sample app. Open a browser on the Compute Engine VM instance and go to 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
On 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:
INSTANCE_CONNECTION_NAME with your instance's Connection name that appears
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created
in the previous Create a user quickstart step.
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.
mvnjetty:run
View the running sample app. Open a browser on the Compute Engine VM instance and go to 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.js
On 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:
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the previous Create a user quickstart step.
Run the Cloud SQL Auth Proxy as a background process. Replace INSTANCE_CONNECTION_NAME with your
instance's Connection name that appears on the Cloud SQL instances page in the Google Cloud console.
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.
Install the Node.js packages necessary to run the app locally.
npminstall
Run the sample app.
npmstart
View the running sample app. Open a browser on the Compute Engine VM instance and go to 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
On 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:
INSTANCE_CONNECTION_NAME with your instance's Connection name that appears
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created
in the previous Create a user quickstart step.
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.
Initialize a virtual environment and install the requirements to run to sample app.
Click the quickstart-instance to see its Overview page
Click the Connections tab.
Under the Security section, click Create client certificate.
In the Create a client certificate dialog,
enter quickstart-key as the name and click Create.
In the New SSL certificate created dialog,
click each download link to download the certificates. Then, click
Close.
Upload SSL certificates to Cloud Storage bucket
Console
In a browser on your local computer, create a Cloud Storage bucket and upload SSL certificates
to the bucket where they can then be accessed from the Compute Engine VM instance.
For Name of your bucket, enter the following name. Replace
YOUR_PROJECT_ID with your project ID:
YOUR_PROJECT_ID-quickstart-certs
Click the Create button to create the bucket.
Click the Upload Files button to upload files to the newly created Cloud Storage bucket.
Select the following files to be uploaded from your local computer to Cloud Storage:
server-ca.pem
client-cert.pem
client-key.pem
gcloud
On your local computer in a terminal or Powershell window open to the directory where you downloaded the SSL certificates,
you can now create a Cloud Storage bucket and upload the SSL certificates to bucket where they can
then be accessed from the Compute Engine VM instance. The gcloud CLI
will be used to upload the files.
From the directory where you downloaded the certificates on your local computer,
run the following gcloud storage cp
commands to copy the SSL certificates to the newly created Cloud Storage bucket:
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a terminal open to the golang-samples/cloudsql/mysql/database-sql
directory, run the following gcloud storage cp commands
to download the SSL certificates from Cloud Storage to the certs directory.
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:
INSTANCE_HOST set to the Private IP address of your instance displayed
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user
that you created in the previous Create a user quickstart step.
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.
Get the dependencies required to run to sample app.
goget./...
Run the sample app.
goruncmd/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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following gcloud compute instances describe command:
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
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 certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a terminal open to the java-docs-samples/cloud-sql/mysql/servlet
directory, run the following gcloud storage cp commands
to download the SSL certificates from Cloud Storage to the current directory.
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.
Run the following commands in the Compute Engine VM instance terminal to import the client certificate and key
into a custom Java keystore using openssl and keytool. Before running the following commands, replace
CLIENT_CERT_KEYSTORE_PASSWD with your own custom client keystore password to be used to create the Java client keystore.
Convert the client key and certificate files to a PKCS #12 archive:
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:
INSTANCE_HOST set to the Private IP address of your instance displayed
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the
previous Create a user quickstart step.
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.
mvnjetty: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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following gcloud compute instances describe command:
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
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.js
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a terminal open to the nodejs-docs-samples/cloud-sql/mysql/mysql
directory, run the following gcloud storage cp commands
to download the SSL certificates from Cloud Storage to the certs directory.
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:
INSTANCE_HOST set to the Private IP address of your instance displayed
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the previous Create a user quickstart step.
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.
Install the Node.js packages necessary to run the app locally.
npminstall
Run the sample app.
npmstart
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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
following gcloud compute instances describe command:
View the running sample app. Open a browser on your local computer and go to
the Compute Engine VM instance's external IP address and port :8080.
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 certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a terminal open to the python-docs-samples/cloud-sql/mysql/sqlalchemy directory,
run the following gcloud storage cp commands
to download the SSL certificates from Cloud Storage to the certs directory.
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:
INSTANCE_HOST set to the Private IP address of your instance displayed
on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the previous Create a user quickstart step.
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.
Initialize a virtual environment and install the requirements to run to sample app.
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.
In a terminal or in Powershell on your local computer, run the following
gcloud compute ssh
command to setup port forwarding over SSH. Before running the command,
replace YOUR_PROJECT_ID with your project ID.
View the running sample app. With port forwarding actively running,
open a browser on your local computer and enter 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 and client certificates on to your local computer
In the Google Cloud console, go to the Cloud SQL Instances page.
Click the quickstart-instance to see its Overview page
Click the Connections tab.
Under the Security section, click Create client certificate.
In the Create a client certificate dialog,
enter quickstart-key as the name and click Create.
In the New SSL certificate created dialog,
click each download link to download the certificates. Then, click
Close.
Upload SSL certificates to Cloud Storage bucket
Console
In a browser on your local computer, create a Cloud Storage bucket and upload SSL certificates
to the bucket where they can then be accessed from the Compute Engine VM instance.
For Name of your bucket, enter the following name. Replace
YOUR_PROJECT_ID with your project ID:
YOUR_PROJECT_ID-quickstart-certs
Click the Create button to create the bucket.
Click the Upload Files button to upload files to the newly created Cloud Storage bucket.
Select the following files to be uploaded from your local computer to Cloud Storage:
server-ca.pem
client-cert.pem
client-key.pem
gcloud
On your local computer in a terminal or Powershell window open to the directory where you downloaded the SSL certificates,
you can now create a Cloud Storage bucket and upload the SSL certificates to bucket where they can
then be accessed from the Compute Engine VM instance. The gcloud CLI
will be used to upload the files.
From the directory where you downloaded the certificates on your local computer,
run the following gcloud storage cp
commands to copy the SSL certificates to the newly created Cloud Storage bucket:
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a Powershell window open to the golang-samples/cloudsql/mysql/database-sql
directory, run the following gcloud storage cp commands
to download the SSL certificates from Cloud Storage to the certs directory.
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:
INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the previous Create a user quickstart step.
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.
Get the dependencies required to run to sample app.
goget./...
Run the sample app.
goruncmd\app\main.go
View the running sample app. Open a browser on the Compute Engine VM instance and go to 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 certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a Powershell window open to the java-docs-samples/cloud-sql/mysql/servlet
directory, run the following gcloud storage cp commands
to download the SSL certificates from Cloud Storage to the current directory.
Configure the SSL certificates for use in Java on the Compute Engine VM instance
In Powershell 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.
Run the following commands in the Compute Engine VM instance Powershell window to import the client certificate and key
into a custom Java keystore using openssl and keytool. Before running the following commands, replace
CLIENT_CERT_KEYSTORE_PASSWD with your own custom client keystore password to be used to create the Java client keystore.
Convert the client key and certificate files to a PKCS #12 archive:
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:
INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the
previous Create a user quickstart step.
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.
mvnjetty:run
View the running sample app. Open a browser on the Compute Engine VM instance and go to 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.js
Download SSL certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a Powershell window open to the nodejs-docs-samples/cloud-sql/mysql/mysql
directory, run the following gcloud storage cp commands
to download the SSL certificates from Cloud Storage to the certs directory.
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:
INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the previous Create a user quickstart step.
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.
Install the Node.js packages necessary to run the app locally.
npminstall
Run the sample app.
npmstart
View the running sample app. Open a browser on the Compute Engine VM instance and go to 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 certificates using the gcloud CLI on the Compute Engine VM instance
On the Compute Engine VM instance in a Powershell window open to the python-docs-samples/cloud-sql/mysql/sqlalchemy
directory, run the following gcloud storage cp commands
to download the SSL certificates from Cloud Storage to the certs directory.
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:
INSTANCE_HOST set to the Private IP address of your instance displayed on the Cloud SQL instances page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the quickstart-user that you created in the previous Create a user quickstart step.
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.
Initialize a virtual environment and install the requirements to run to sample app.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-30 UTC."],[],[]]