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 accountto 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 thegcloud CLIwhich provides
command-line access to your Google Cloud resources. Thegcloud CLIis used
to run thegcloud CLIcommands presented throughout this quickstart.
All the commands are formatted to be run in a terminal or a Powershell window.
Run the followinggcloudcommand:
gcloud services enable sqladmin.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 theCloud SQL Instancespage.
In thePasswordfield, enter a password for
the root user. Save this password for future use.
In theChoose region and zonal availabilitysection, selectSingle zone.
Expand theShow Configurationssection.
In theMachine Typedrop-down list, selectLightweight.
ClickCreate Instanceand then wait
until the instance initializes and starts.
gcloud
Create an instance with a public IP address
Before running thegcloud sql instances createcommand as follows, replaceDB_ROOT_PASSWORDwith 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 thegcloud database versionsdocumentation 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 defaultus-centralis used.
See the full list ofregions.
gcloud compute addresses creategoogle-managed-services-default--global --purpose=VPC_PEERING --prefix-length=16 --description="peering range for Google" --network=default
Run thegcloud services vpc-peerings connectcommand 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, replaceDB_ROOT_PASSWORDwith 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 thegcloud database versionsdocumentation 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 defaultus-central1is used.
See the full list ofregions.
To open theOverviewpage of an instance, click the instance name.
SelectUsersfrom the SQL navigation menu.
ClickAdd user account.
In theAdd a user account to instanceinstance_namepage,
add the following information:
Username: Set toquickstart-user
Password: Specify a password for your database user.
Make a note of this for use in a later step of this quickstart.
In theHost namesection, the default isAllow any host,
which means that the user can connect from any IP address.
Optionally, selectRestrict host by IP address or address rangeand enter an IP address or address range in theHostsection.
The user can then connect only from the IP address or
addresses specified.
ClickAdd.
gcloud
Before running the following command, make the following replacements:
PASSWORDwith 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 theCloud 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 account
In the Google Cloud console, go to theCreate service accountpage.
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 account
To grant your service account theCloud SQL Clientrole
and theStorage Object Viewerrole on your project, run thegcloud projects add-iam-policy-bindingcommand. ReplacePROJECT_IDwith your Google Cloud project ID:
In the list of virtual machine instances, clickSSHin 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, seeSSH connections to Linux VMs
gcloud
Use thegcloud compute sshcommand to connect
to a Linux VM instance. ReplaceYOUR_PROJECT_IDwith 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 theGoogle Cloud console. After you install the plugin,
connect to any Windows Server instance by using theRDPbutton in
theGoogle Cloud console.
To connect using the Chrome RDP plugin, do the following:
Complete the instructions in theInstalling Pythonsection.
The instructions above will have you visit thePython Releases
for Windowsdownload page. From that page click theLatest Python 3 Releaselink.
On the Python 3.X.X page, click theWindows Installer 64-bitlink 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 selectRun as administrator.
In theInstall Pythondialog that appears, select the
option toAdd Python 3.X.X to PATHand click→ Install Now.
Use PIP to install virtualenv.
Open Powershell on the Windows Compute Engine VM instance and
run the followingpip installcommand.
pip install virtualenv
Install Git
InstallGit, an open source version control system
on to your Compute Engine VM instance.
Run the suggestedDebian/Ubuntuinstall gitcommand using thesudocommand 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 officialGit installation
documentation for Windowsto download the64-bit Standalone Installerand run it to install Git.
Clone sample app
Clone a sample app to your Compute Engine VM instance using thegit clonecommand.
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.
cd golang-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.
cd java-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.
cd nodejs-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.
cd python-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_NAMEwith your instance'sConnection namethat appears
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created
in the previousCreate a userquickstart 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.
go get ./...
Run the sample app.
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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
followinggcloud compute instances describecommand:
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, pressControl+Cin 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_NAMEwith your instance'sConnection namethat appears
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created
in the previousCreate a userquickstart 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.
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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
followinggcloud compute instances describecommand:
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, pressControl+Cin 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_PASSWORDwith the password of thequickstart-userthat you created in the previousCreate a userquickstart step.
Set permissions to make the Cloud SQL Auth Proxy file executable.
chmod +x cloud-sql-proxy
Run the Cloud SQL Auth Proxy as a background process. ReplaceINSTANCE_CONNECTION_NAMEwith your
instance'sConnection namethat appears on theCloud SQL instancespage 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.
npm install
Run the sample app.
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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
followinggcloud compute instances describecommand:
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, pressControl+Cin 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_NAMEwith your instance'sConnection namethat appears
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created
in the previousCreate a userquickstart 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 upport forwarding over SSHby 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 followinggcloud compute sshcommand to setup port forwarding over SSH. Before running the command,
replaceYOUR_PROJECT_IDwith your project ID.
View the running sample app. With port forwarding actively running,
open a browser on your local computer and enterhttp://127.0.0.1:8000in the address bar of your browser..
To stop the sample app, pressControl+Cin 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_NAMEwith your instance'sConnection namethat appears
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created
in the previousCreate a userquickstart 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.
go get ./...
Run the sample app.
go run cmd\app\main.go
View the running sample app. Open a browser on the Compute Engine VM instance and go tohttp://127.0.0.1:8080.
To stop the sample app, pressControl+Cin 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_NAMEwith your instance'sConnection namethat appears
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created
in the previousCreate a userquickstart 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.
mvn jetty:run
View the running sample app. Open a browser on the Compute Engine VM instance and go tohttp://127.0.0.1:8080.
To stop the sample app, pressControl+Cin 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_PASSWORDwith the password of thequickstart-userthat you created in the previousCreate a userquickstart step.
Run the Cloud SQL Auth Proxy as a background process. ReplaceINSTANCE_CONNECTION_NAMEwith your
instance'sConnection namethat appears on theCloud SQL instancespage 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.
npm install
Run the sample app.
npm start
View the running sample app. Open a browser on the Compute Engine VM instance and go tohttp://127.0.0.1:8080.
To stop the sample app, pressControl+Cin 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_NAMEwith your instance'sConnection namethat appears
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created
in the previousCreate a userquickstart 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 thequickstart-instanceto see itsOverviewpage
Click theConnectionstab.
Under theSecuritysection, clickCreate client certificate.
In theCreate a client certificatedialog,
enterquickstart-keyas the name and clickCreate.
In theNew SSL certificate createddialog,
click each download link to download the certificates. Then, clickClose.
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.
ForName of your bucket, enter the following name. ReplaceYOUR_PROJECT_IDwith your project ID:
YOUR_PROJECT_ID-quickstart-certs
Click theCreatebutton to create the bucket.
Click theUpload Filesbutton 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. Thegcloud CLIwill be used to upload the files.
From the directory where you downloaded the certificates on your local computer,
run the followinggcloud storage cpcommands 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 thegolang-samples/cloudsql/mysql/database-sqldirectory, run the followinggcloud storage cpcommands
to download the SSL certificates from Cloud Storage to thecertsdirectory.
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_HOSTset to thePrivate IP addressof your instance displayed
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created in the previousCreate a userquickstart 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.
go get ./...
Run the sample app.
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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
followinggcloud compute instances describecommand:
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, pressControl+Cin 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 thejava-docs-samples/cloud-sql/mysql/servletdirectory, run the followinggcloud storage cpcommands
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, replaceTRUST_CERT_KEYSTORE_PASSWDwith 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, replaceCLIENT_CERT_KEYSTORE_PASSWDwith 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_HOSTset to thePrivate IP addressof your instance displayed
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created in the
previousCreate a userquickstart 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.
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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
followinggcloud compute instances describecommand:
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, pressControl+Cin 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 thenodejs-docs-samples/cloud-sql/mysql/mysqldirectory, run the followinggcloud storage cpcommands
to download the SSL certificates from Cloud Storage to thecertsdirectory.
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_HOSTset to thePrivate IP addressof your instance displayed
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created in the previousCreate a userquickstart 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.
npm install
Run the sample app.
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.
In a terminal or in Powershell on your local computer, get the Compute Engine VM instance's external IP address by running the
followinggcloud compute instances describecommand:
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, pressControl+Cin 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 thepython-docs-samples/cloud-sql/mysql/sqlalchemydirectory,
run the followinggcloud storage cpcommands
to download the SSL certificates from Cloud Storage to thecertsdirectory.
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_HOSTset to thePrivate IP addressof your instance displayed
on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created in the previousCreate a userquickstart 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 upport forwarding over SSHby 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 followinggcloud compute sshcommand to setup port forwarding over SSH. Before running the command,
replaceYOUR_PROJECT_IDwith your project ID.
View the running sample app. With port forwarding actively running,
open a browser on your local computer and enterhttp://127.0.0.1:8000in the address bar of your browser.
To stop the sample app, pressControl+Cin 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 theCloud SQL Instancespage.
Click thequickstart-instanceto see itsOverviewpage
Click theConnectionstab.
Under theSecuritysection, clickCreate client certificate.
In theCreate a client certificatedialog,
enterquickstart-keyas the name and clickCreate.
In theNew SSL certificate createddialog,
click each download link to download the certificates. Then, clickClose.
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.
ForName of your bucket, enter the following name. ReplaceYOUR_PROJECT_IDwith your project ID:
YOUR_PROJECT_ID-quickstart-certs
Click theCreatebutton to create the bucket.
Click theUpload Filesbutton 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. Thegcloud CLIwill be used to upload the files.
From the directory where you downloaded the certificates on your local computer,
run the followinggcloud storage cpcommands 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 thegolang-samples/cloudsql/mysql/database-sqldirectory, run the followinggcloud storage cpcommands
to download the SSL certificates from Cloud Storage to thecertsdirectory.
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_HOSTset to thePrivate IP addressof your instance displayed on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created in the previousCreate a userquickstart 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.
go get ./...
Run the sample app.
go run cmd\app\main.go
View the running sample app. Open a browser on the Compute Engine VM instance and go tohttp://127.0.0.1:8080.
To stop the sample app, pressControl+Cin 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 thejava-docs-samples/cloud-sql/mysql/servletdirectory, run the followinggcloud storage cpcommands
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, replaceTRUST_CERT_KEYSTORE_PASSWDwith 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, replaceCLIENT_CERT_KEYSTORE_PASSWDwith 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_HOSTset to thePrivate IP addressof your instance displayed on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created in the
previousCreate a userquickstart 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.
mvn jetty:run
View the running sample app. Open a browser on the Compute Engine VM instance and go tohttp://127.0.0.1:8080.
To stop the sample app, pressControl+Cin 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 thenodejs-docs-samples/cloud-sql/mysql/mysqldirectory, run the followinggcloud storage cpcommands
to download the SSL certificates from Cloud Storage to thecertsdirectory.
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_HOSTset to thePrivate IP addressof your instance displayed on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created in the previousCreate a userquickstart 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.
npm install
Run the sample app.
npm start
View the running sample app. Open a browser on the Compute Engine VM instance and go tohttp://127.0.0.1:8080.
To stop the sample app, pressControl+Cin 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 thepython-docs-samples/cloud-sql/mysql/sqlalchemydirectory, run the followinggcloud storage cpcommands
to download the SSL certificates from Cloud Storage to thecertsdirectory.
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_HOSTset to thePrivate IP addressof your instance displayed on theCloud SQL instancespage in the Google Cloud console.
YOUR_DB_PASSWORDwith the password of thequickstart-userthat you created in the previousCreate a userquickstart 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.