# Connect to Cloud SQL for MySQL from Compute Engine

<br />

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

> [!NOTE]
> **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.

1. [Verify that you have the permissions required to complete this guide](https://docs.cloud.google.com/sql/docs/mysql/connect-instance-compute-engine.md.txt#required-roles).
2. Enable the Cloud APIs necessary to run a Cloud SQL sample app on a Compute Engine VM instance.

   ### Console

   Click the **Enable APIs** button to enable the API required for this quickstart.

   [Enable APIs](https://console.cloud.google.com/apis/enableflow?apiid=sqladmin.googleapis.com)

   This enables the following API:
   - Cloud SQL Admin API

   ### gcloud

   [Install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) which provides
   command-line access to your Google Cloud resources. The [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) 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:

   ```bash
   gcloud services enable sqladmin.googleapis.com
   ```

   This command enables the following API:
   - Cloud SQL Admin API
3. If your Compute Engine VM or VPC network restricts outbound traffic, verify that your firewall rules allow outgoing TCP connections on the required destination ports:
   - **Direct connections over public IP, private IP, or
     Private Service Connect:** Port `3306`, the default MySQL port, on your Cloud SQL instance's IP address.
   - **Cloud SQL Auth Proxy or Cloud SQL Language Connectors:** Port `3307` on your Cloud SQL instance's IP address and port `443` for `sqladmin.googleapis.com` API requests.

### Required roles


To get the permissions that
you need to complete this quickstart,

ask your administrator to grant you the
following IAM roles:

- [Billing Account Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/billing.md.txt#billing.viewer) (`roles/billing.viewer`) on organization
- [Cloud SQL Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/cloudsql.md.txt#cloudsql.admin) (`roles/cloudsql.admin`) on project
- [Compute Instance Admin (v1)](https://docs.cloud.google.com/iam/docs/roles-permissions/compute.md.txt#compute.instanceAdmin.v1) (`roles/compute.instanceAdmin.v1`) on project
- [Dev Ops](https://docs.cloud.google.com/iam/docs/roles-permissions/jobfunctions.md.txt#iam.devOps) (`roles/iam.devOps`) on project
- [Project IAM Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/resourcemanager.md.txt#resourcemanager.projectIamAdmin) (`roles/resourcemanager.projectIamAdmin`) on project
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on project
- [Service Usage Consumer](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageConsumer) (`roles/serviceusage.serviceUsageConsumer`) on project
- [Storage Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/storage.md.txt#storage.admin) (`roles/storage.admin`) on project


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## Set up Cloud SQL


### Create a Cloud SQL instance

#### Public IP

### Console

#### Create an instance with a public IP address

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. Click **Create instance**.
3. From the **Create instance** menu, select **New instance**.
4. Click **Choose MySQL**.
5. Make sure that **Enterprise Plus** is selected as the Cloud SQL edition for your instance.
6. In the **Instance ID** field, enter `quickstart-instance`.
7. In the **Password** field, enter a password for the root user. Save this password for future use.
8. In the **Choose region and zonal availability** section, select **Single zone**.
9. In the **Customize your instance** section, click **Show configuration options**.
10. Expand the **Machine configuration** node.
11. From the **Machine shapes** region, select the **4 vCPU, 32 GB** shape.
12. 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`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create.md.txt)
command as follows, replace <var translate="no">DB_ROOT_PASSWORD</var> 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](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create.md.txt#--database-version) 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](https://docs.cloud.google.com/sql/docs/instance-locations).


Run the [`gcloud
sql instances create`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create) command to create a Cloud SQL instance.

```bash
gcloud sql instances create quickstart-instance --database-version=MYSQL_8_0 --cpu=1 --memory=4GB --region=us-central1 --root-password=DB_ROOT_PASSWORD
```

<br />

<br />

<br />

<br />

#### Private IP

### Console

#### Allocate an IP address range and create a private connection to configure private services access for Cloud SQL

1. In the Google Cloud console, go to the **VPC networks** page.

   [Go to VPC networks](https://console.cloud.google.com/networking/networks)
2. Select the `default` VPC network.
3. Select the **Private service connection** tab.
4. Select the **Allocated IP ranges for services** tab.
5. Click **Allocate IP range**.
6. For the **Name** of the allocated range, specify `google-managed-services-default`.
7. Select the **Automatic** option for IP range and specify the prefix length as `16`.
8. Click **Allocate** to create the allocated range.
9. Select the **Private connections to services** tab for the `default` VPC network.
10. Click **Create connection** to create a private connection between your network and a service producer.
11. For the **Assigned allocation** , select `google-managed-services-default`.
12. Click **Connect** to create the connection.

#### Create an instance with private IP address and SSL enabled

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. Click **Create instance**.
3. From the **Create instance** menu, select **New instance**.
4. Click **Choose MySQL**.
5. Make sure that **Enterprise Plus** is selected as the Cloud SQL edition for your instance.
6. In the **Instance ID** field, enter `quickstart-instance`.
7. In the **Password** field, enter a password for the root user. Save this password for future use.
8. In the **Choose region and zonal availability** section, select **Single zone**.
9. In the **Customize your instance** section, click **Show configuration options**.
10. Expand the **Machine configuration** node.
11. From the **Machine shapes** region, select the **4 vCPU, 32 GB** shape.
12. Expand the **Connections** node.
13. Clear the **Public IP** checkbox to create an instance only with a private IP address.
14. Select the **Private IP** checkbox.
15. From the **Network** menu, select **default**.
16. Click **Create instance** and then wait for the instance to initialize and start.
17. Click **Connections**.
18. In the **Security** section, select **Allow only SSL connections** to enable SSL connections.
19. In the **Enable SSL** dialog, click **Enable and restart** and then wait for the instance to restart.

### gcloud

#### Allocate an IP address range and create a private connection to configure private services access for Cloud SQL

1.
   Run the [`gcloud compute addresses create`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/addresses/create.md.txt)
   command to allocate an IP address range.

   ```bash
   gcloud compute addresses create google-managed-services-default --global --purpose=VPC_PEERING --prefix-length=16 --description="peering range for Google" --network=default
   ```
2.
   Run the [`gcloud services vpc-peerings connect`](https://docs.cloud.google.com/sdk/gcloud/reference/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.

   ```bash
   gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com --ranges=google-managed-services-default --network=default --project=YOUR_PROJECT_ID
   ```

#### Create an instance with private IP address and SSL enabled

1. Before running the command as follows, replace <var translate="no">DB_ROOT_PASSWORD</var> with the password of your database user.

2. 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](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create.md.txt#--database-version) 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](https://docs.cloud.google.com/sql/docs/instance-locations).
3. Run the [`gcloud
   sql instances create`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create) command to create a Cloud SQL instance with a Private IP address.

```bash
gcloud beta sql instances create quickstart-instance --database-version=MYSQL_8_0 --cpu=1 --memory=4GB --region=us-central1 --root-password=DB_ROOT_PASSWORD --no-assign-ip --network=default
```
4.
   Run the [`gcloud sql instances patch`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/patch.md.txt)
   command to enable **only allow SSL connections** for the instance.

```bash
gcloud sql instances patch quickstart-instance --require-ssl
```

### Create a database

### Console

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. Select `quickstart-instance`.
3. Open the **Databases** tab.
4. Click **Create database**.
   1. In the **Create a database** dialog box, enter `quickstart_db` as the name of the database, and optionally the character set and collation.
   2. Click **Create**.

### gcloud

Run the [`gcloud
sql databases create`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/databases/create) command to create a database.

```bash
gcloud sql databases create quickstart_db --instance=quickstart-instance
```

### Create a user

### Console

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. To open the **Overview** page of an instance, click the instance name.
3. Select **Users** from the SQL navigation menu.
4. 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.
5. Click **Add**.

### gcloud

Before running the following command, make the following replacements:

1. <var translate="no">PASSWORD</var> with a password for your database user. Make a note of this for use in a later step of this quickstart.

Run the [`gcloud sql users create`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/users/create) command to create the user.

```bash
gcloud sql users create quickstart-user --instance=quickstart-instance --password=PASSWORD
```

Username 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

1. In the Google Cloud console, go to the **Create service account** page.
2. [Go to Create service account](https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts/create)
3. Select a Google Cloud project.
4. Enter a `quickstart-service-account` as the service account name.
5. Optional: Enter a description of the service account.
6. Click **Create and continue** and continue to the next step.
7. Choose the **Cloud SQL Client** role to grant to the service account on the project.
8. Click **Add another role** and choose the **Storage Object Viewer** role to grant to the service account on the project.
9. Click **Continue**.
10. Click **Done** to finish creating the service account.

### gcloud

#### Create a service account

1. To create the service account, run the [`gcloud iam service-accounts create`](https://docs.cloud.google.com/sdk/gcloud/reference/iam/service-accounts/create) command:

```bash
gcloud iam service-accounts create quickstart-service-account --description="DESCRIPTION" --display-name="quickstart-service-account"
```
2. Replace the following value:
   - <var translate="no">`DESCRIPTION`</var>: an optional description of the service account
3. 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`](https://docs.cloud.google.com/sdk/gcloud/reference/projects/add-iam-policy-binding) command. Replace <var translate="no">PROJECT_ID</var> with your Google Cloud project ID:

   ```bash
   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 Compute Engine VM instance


Create a Compute Engine VM Instance to host a sample web app that connects to Cloud SQL.

#### Create a Linux VM Instance

### Console

1. In the Google Cloud console, go to the **VM instances** page.

   [Go to VM instances](https://console.cloud.google.com/compute/instances)
2. Click the **Create instance** button.
3. For VM instance **Name** enter `quickstart-vm-instance`.
4. For **Service accounts** select `quickstart-service-account`.
5. For **Firewall** select the **Allow HTTP traffic** option.
6. Click **Create** to create the VM instance.

### gcloud

Before running the following command, replace <var translate="no">YOUR_PROJECT_ID</var> with your project ID.

Run the following [`gcloud compute instances create`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/create.md.txt) command.

```bash
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-a
```

#### Create a Windows VM Instance

### Console

1. In the Google Cloud console, go to the **VM instances** page.

   [Go to VM instances](https://console.cloud.google.com/compute/instances)
2. Click the **Create instance** button.
3. For VM instance **Name** enter `quickstart-vm-instance`.
4. For **Boot disc** click the **Change** button.
   1. For **Operating system** select **Windows Server**.
   2. For **Version** select **Windows Server 2022 Datacenter**.
   3. Click the **Select** button.
5. For **Service accounts** select `quickstart-service-account`.
6. For **Firewall** select the **Allow HTTP traffic** option.
7. Click **Create** to create the VM instance.
8. After 2-3 minutes once the VM instance has started, click the **Set Windows Password** button on the VM instance details page.
9. 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.

### gcloud

Before running the following command, replace <var translate="no">YOUR_PROJECT_ID</var> with your project ID.

Run the following [`gcloud compute instances create`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/create.md.txt) command in a Terminal Window.

```bash
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.

```bash
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

### Console

- In the Google Cloud console, go to the **VM instances** page.

  [Go to VM instances](https://console.cloud.google.com/compute/instances)
- In the list of virtual machine instances, click **SSH** in the row of the instance that you want to connect to.

  ![SSH button next to instance name.](https://docs.cloud.google.com/static/docs/images/establish-ssh-connection-1.png)
- 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](https://docs.cloud.google.com/compute/docs/instances/ssh.md.txt)

### gcloud

Use the
[`gcloud compute ssh`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/ssh) command to connect
to a Linux VM instance. Replace <var translate="no">YOUR_PROJECT_ID</var> with your project ID:

```bash
gcloud compute ssh --project=YOUR_PROJECT_ID --zone=us-central1-a quickstart-vm-instance
```

#### Access Windows VM Instance

### RDP client

You can use a Remote Desktop Protocol (RDP) client, such as the Microsoft
Remote Desktop Connection app, to connect to your Windows VM instance by
downloading the instance's RDP configuration file from the
[Google Cloud console](https://console.cloud.google.com/).


To connect using an RDP client, do the following:

1. If you don't already have an RDP client installed on your local machine, install one. For a list of supported clients, see [Microsoft
   Remote Desktop clients](https://docs.microsoft.com/windows-server/remote/remote-desktop-services/clients/remote-desktop-clients).
2. In the Google Cloud console, go to the **VM instances** page and find the Windows instance that you want to connect to.

   [Go to the VM instances page](https://console.cloud.google.com/compute/instances)
3. Click the **RDP** menu for the instance that you want to connect to, and then select **Download the RDP file** to download the RDP file for your instance.
4. Open the downloaded RDP file in your RDP client.
5. When prompted, enter the username and password that you created for your VM instance. Because your VM instance doesn't have a domain configured, leave the **Domain** field blank if prompted.
6. If prompted, accept the certificate to complete the connection.

### Other


See [Connect to Windows VMs using RDP](https://docs.cloud.google.com/compute/docs/instances/connecting-to-windows.md.txt) for more options for accessing a Compute Engine Windows VM instance.

## Setup development environment for programming language


Set up the Compute Engine VM instance's development environment for your preferred programming language.

#### Setup Linux VM Instance development environment

### Go


Complete the following steps to set up the Compute Engine VM instance's development environment to run the Go sample app.

1. Go to the [setup guide for a Go development environment](https://docs.cloud.google.com/go/docs/setup.md.txt).
2. Complete the instructions in the **Install Go** section.

### Java


Complete the following steps to set up the Compute Engine VM instance's development environment to run the Java sample app.

1. Go to the [setup guide for a Java development environment](https://docs.cloud.google.com/java/docs/setup.md.txt).
2. Complete the instructions in the **Install a JDK (Java Development Kit)** section.
3. Complete the instructions in the **Install a build automation tool** to set up Apache Maven.

### Node.js


Complete the following steps to set up the Compute Engine VM instance's development environment to run the Node.js sample app.

1. Go to [setup guide for a Node.js development environment](https://docs.cloud.google.com/nodejs/docs/setup.md.txt).
2. Complete the instructions in the **Installing Node.js and npm** section.

### Python


Complete the following steps to set up the Compute Engine VM instance's development environment to run the Python sample app.

1. Go to [setup guide for a Python development environment](https://docs.cloud.google.com/python/docs/setup.md.txt).
2. Complete the instructions in the **Installing Python** section.

#### Setup Windows VM Instance development environment

### Go


Complete the following steps to set up the Compute Engine VM instance's development environment to run the Go sample app.

1. Go to the [setup guide for a Go development environment](https://docs.cloud.google.com/go/docs/setup.md.txt).
2. Complete the instructions in the **Install Go** section.

### Java


Complete the following steps to set up the Compute Engine VM instance's development environment to run the Java sample app.

1. Go to the [setup guide for a Java development environment](https://docs.cloud.google.com/java/docs/setup.md.txt).
2. Complete the instructions in the **Install a JDK (Java Development Kit)** section.
3. Complete the instructions in the **Install a build automation tool** section to set up Apache Maven.

### Node.js


Complete the following steps to set up the Compute Engine VM instance's development environment to run the Node.js sample app.

1. Go to [setup guide for a Node.js development environment](https://docs.cloud.google.com/nodejs/docs/setup.md.txt).
2. Complete the instructions in the **Installing Node.js and npm** section.

### Python


Complete the following steps to set up the Compute Engine VM instance's development environment to run the Python sample app.

1. Install Python and the PIP package manager for Python.
   1. Go to [setup guide for a Python development environment](https://docs.cloud.google.com/python/docs/setup.md.txt).
   2. Complete the instructions in the **Installing Python** section.
      1. The instructions above will have you visit the **Python Releases
         for Windows** download page. From that page click the **Latest Python 3 Release** link.
      2. 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.
      3. 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**.
      4. In the **Install Python** dialog that appears, select the option to **Add Python 3.X.X to PATH** and click **→ Install Now**.
2. Use PIP to install virtualenv.
   1. Open Powershell on the Windows Compute Engine VM instance and run the following `pip install` command.

   ```bash
   pip install virtualenv
   ```

## Install Git


Install [Git](https://git-scm.com/), an open source version control system
on to your Compute Engine VM instance.

#### Compute Engine Linux VM instance


On your Compute Engine Linux VM instance, follow the official
[Git
installation documentation for Linux](https://git-scm.com/download/linux).

- Run the suggested **Debian/Ubuntu** `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 git
```

#### Compute Engine Windows VM instance


On your Compute Engine Windows VM instance, follow the official
[Git installation
documentation for Windows](https://git-scm.com/download/win) 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`](https://git-scm.com/docs/git-clone) command.

<br />

### 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.

1. Clone the sample app.

   ```bash
   git clone https://github.com/GoogleCloudPlatform/golang-samples
   ```
2. Change directory to the directory containing the sample app.

   ```bash
   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.

1. Clone the sample app.

   ```bash
   git clone https://github.com/GoogleCloudPlatform/java-docs-samples
   ```
2. Change directory to the directory containing the sample app.

   ```bash
   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.

1. Clone the sample app.

   ```bash
   git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
   ```
2. Change directory to the directory containing the sample app.

   ```bash
   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.

1. Clone the sample app.

   ```bash
   git clone https://github.com/GoogleCloudPlatform/python-docs-samples
   ```
2. Change directory to the directory containing the sample app.

   ```bash
   cd python-docs-samples/cloud-sql/mysql/sqlalchemy
   ```

<br />

## 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:

- <var translate="no">INSTANCE_CONNECTION_NAME</var> with your instance's **Connection name** that appears on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.
- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME'
export DB_PORT='3306'
export DB_NAME='quickstart_db'
export DB_USER='quickstart-user'
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.

1. Get the dependencies required to run to sample app.

   ```bash
   go get ./...
   ```
2. Run the sample app.

   ```bash
   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]
> **Note:** This quickstart step requires the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt), which provides command-line access to your Google Cloud resources using `gcloud CLI` commands. If you don't have the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) installed on your local computer, then [install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) to proceed.

1. 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`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/describe) command:

```bash
gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
```
2. 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.

   ```bash
   http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
   ```

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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:

- <var translate="no">INSTANCE_CONNECTION_NAME</var> with your instance's **Connection name** that appears on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.
- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME'
export DB_PORT='3306'
export DB_NAME='quickstart_db'
export DB_USER='quickstart-user'
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.

```bash
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]
> **Note:** This quickstart step requires the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt), which provides command-line access to your Google Cloud resources using `gcloud CLI` commands. If you don't have the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) installed on your local computer, then [install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) to proceed.

1. 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`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/describe) command:

```bash
gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
```
2. 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.

   ```bash
   http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
   ```

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> in the Compute Engine VM instance terminal where you started the sample app.

### Node.js

1.
   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:

   - <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

   ```bash
   export INSTANCE_HOST='127.0.0.1'
   export DB_PORT='3306'
   export DB_NAME='quickstart_db'
   export DB_USER='quickstart-user'
   export DB_PASS='YOUR_DB_PASSWORD'
   ```
2. Download the Cloud SQL Auth Proxy.

   ```bash
   curl -o cloud-sql-proxy \
   https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.0.0/cloud-sql-proxy.linux.amd64
   ```
3. Set permissions to make the Cloud SQL Auth Proxy file executable.

   ```bash
   chmod +x cloud-sql-proxy
   ```
4. Run the Cloud SQL Auth Proxy as a background process. Replace <var translate="no">INSTANCE_CONNECTION_NAME</var> with your instance's **Connection name** that appears on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

   ```bash
   ./cloud-sql-proxy INSTANCE_CONNECTION_NAME &
   ```

> [!NOTE]
> **Note:** The process running the Cloud SQL Auth Proxy in the background can be stopped using the `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.

1. Install the Node.js packages necessary to run the app locally.

   ```bash
   npm install
   ```
2. Run the sample app.

   ```bash
   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]
> **Note:** This quickstart step requires the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt), which provides command-line access to your Google Cloud resources using `gcloud CLI` commands. If you don't have the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) installed on your local computer, then [install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) to proceed.

1. 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`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/describe) command:

```bash
gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
```
2. 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.

   ```bash
   http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
   ```

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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:

- <var translate="no">INSTANCE_CONNECTION_NAME</var> with your instance's **Connection name** that appears on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.
- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
export INSTANCE_CONNECTION_NAME='INSTANCE_CONNECTION_NAME'
export DB_PORT='3306'
export DB_NAME='quickstart_db'
export DB_USER='quickstart-user'
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.

1. Initialize a virtual environment and install the requirements to run to sample app.

   ```bash
   python3 -m venv env
   source env/bin/activate
   pip install -r requirements.txt
   ```
2. Run the sample app.

   ```bash
   python app.py
   ```


On your local computer, set up
[port forwarding over SSH](https://docs.cloud.google.com/solutions/connecting-securely.md.txt#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]
> **Note:** This quickstart step requires the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt), which provides command-line access to your Google Cloud resources using `gcloud CLI` commands. If you don't have the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) installed on your local computer, then [install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) to proceed.

1. In a terminal or in Powershell on your local computer, run the following [`gcloud compute ssh`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/ssh) command to setup port forwarding over SSH. Before running the command, replace <var translate="no">YOUR_PROJECT_ID</var> with your project ID.

```bash
gcloud compute ssh quickstart-vm-instance --project=YOUR_PROJECT_ID --zone=us-central1-a --ssh-flag='-L 8000:127.0.0.1:8080'
```
2. 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..

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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:

- <var translate="no">INSTANCE_CONNECTION_NAME</var> with your instance's **Connection name** that appears on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.
- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME"
$env:DB_PORT="3306"
$env:DB_NAME="quickstart_db"
$env:DB_USER="quickstart-user"
$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.

1. Get the dependencies required to run to sample app.

   ```bash
   go get ./...
   ```
2. Run the sample app.

   ```bash
   go run cmd\app\main.go
   ```
3. View the running sample app. Open a browser on the Compute Engine VM instance and go to `http://127.0.0.1:8080`.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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:

- <var translate="no">INSTANCE_CONNECTION_NAME</var> with your instance's **Connection name** that appears on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.
- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME"
$env:DB_PORT="3306"
$env:DB_NAME="quickstart_db"
$env:DB_USER="quickstart-user"
$env:DB_PASS="YOUR_DB_PASSWORD"
```

1.
   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.

   ```bash
   mvn jetty:run
   ```
2. View the running sample app. Open a browser on the Compute Engine VM instance and go to `http://127.0.0.1:8080`.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> in the Compute Engine
VM instance Powershell window where you started the sample app.

### Node.js

1.
   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:

   - <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

   ```bash
   $env:INSTANCE_HOST="127.0.0.1"
   $env:DB_PORT="3306"
   $env:DB_NAME="quickstart_db"
   $env:DB_USER="quickstart-user"
   $env:DB_PASS="YOUR_DB_PASSWORD"
   ```
2. Download the Cloud SQL Auth Proxy.

   ```bash
   wget https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.0.0/cloud-sql-proxy.x64.exe `
   -O cloud-sql-proxy.exe
   ```
3. Run the Cloud SQL Auth Proxy as a background process. Replace <var translate="no">INSTANCE_CONNECTION_NAME</var> with your instance's **Connection name** that appears on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

   ```bash
   Start-Process -filepath  ".\cloud-sql-proxy.exe" -ArgumentList `
   "INSTANCE_CONNECTION_NAME"
   ```

> [!NOTE]
> **Note:** The process running the Cloud SQL Auth Proxy in the background can be stopped by selecting the **cmd.exe** window that was spawned by the `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.

1. Install the Node.js packages necessary to run the app locally.

   ```bash
   npm install
   ```
2. Run the sample app.

   ```bash
   npm start
   ```
3. View the running sample app. Open a browser on the Compute Engine VM instance and go to `http://127.0.0.1:8080`.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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:

- <var translate="no">INSTANCE_CONNECTION_NAME</var> with your instance's **Connection name** that appears on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.
- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
$env:INSTANCE_CONNECTION_NAME="INSTANCE_CONNECTION_NAME"
$env:DB_PORT="3306"
$env:DB_NAME="quickstart_db"
$env:DB_USER="quickstart-user"
$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.

1. Initialize a virtual environment and install the requirements to run to sample app.

   ```bash
   virtualenv --python python3 env
   .\env\Scripts\activate
   pip install -r requirements.txt
   ```
2. Run the sample app.

   ```bash
   python app.py
   ```
3. View the running sample app. Open a browser on the Compute Engine VM instance and go to `http://127.0.0.1:8080`.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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 and client certificates on to your local computer

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. Click the `quickstart-instance` to see its **Overview** page
3. Click the **Connections** tab.
4. Under the **Security** section, click **Create client certificate**.
5. In the **Create a client certificate** dialog, enter `quickstart-key` as the name and click **Create**.
6. In the **New SSL certificate created** dialog,
   click each download link to download the certificates. Then, click
   **Close**.


   > [!WARNING]
   > **Important:** Store this private key securely. If you lose it, you must create a new client certificate.

   <br />

#### 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.

1. [Create a Cloud Storage bucket](https://console.cloud.google.com/storage/create-bucket).
   1. For **Name of your bucket** , enter the following name. Replace <var translate="no">YOUR_PROJECT_ID</var> with your project ID:

      ```bash
      YOUR_PROJECT_ID-quickstart-certs
      ```
   2. Click the **Create** button to create the bucket.
2. Click the **Upload Files** button to upload files to the newly created Cloud Storage bucket.
3. 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](https://docs.cloud.google.com/sdk/gcloud.md.txt)
will be used to upload the files.

1. Run the following [`gcloud storage buckets create`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/buckets/create.md.txt) command to make a new Cloud Storage bucket:

```bash
gcloud storage buckets create gs://YOUR_PROJECT_ID-quickstart-certs --location=us-central1
```
2. From the directory where you downloaded the certificates on your local computer, run the following [`gcloud storage cp`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands to copy the SSL certificates to the newly created Cloud Storage bucket:

```bash
gcloud storage cp server-ca.pem gs://YOUR_PROJECT_ID-quickstart-certs/
gcloud storage cp client-cert.pem gs://YOUR_PROJECT_ID-quickstart-certs/
gcloud storage cp client-key.pem gs://YOUR_PROJECT_ID-quickstart-certs/
```

### Go

#### 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`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands
to download the SSL certificates from Cloud Storage to the `certs` directory.

```bash
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-cert.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-key.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:

- <var translate="no">INSTANCE_HOST</var> set to the **Private IP address** of your instance displayed on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

> [!NOTE]
> **Note:** Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. For Non-RFC 1918 address ranges, see [Learn about using private IP](https://docs.cloud.google.com/sql/docs/mysql/private-ip.md.txt#network_issues).

- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
export INSTANCE_HOST='INSTANCE_HOST'
export DB_PORT='3306'
export DB_NAME='quickstart_db'
export DB_USER='quickstart-user'
export DB_PASS='YOUR_DB_PASSWORD'
export DB_ROOT_CERT='certs/server-ca.pem'
export DB_CERT='certs/client-cert.pem'
export DB_KEY='certs/client-key.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.

1. Get the dependencies required to run to sample app.

   ```bash
   go get ./...
   ```
2. Run the sample app.

   ```bash
   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]
> **Note:** This quickstart step requires the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt), which provides command-line access to your Google Cloud resources using `gcloud CLI` commands. If you don't have the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) installed on your local computer, then [install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) to proceed.

1. 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`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/describe) command:

```bash
gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
```
2. 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.

   ```bash
   http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
   ```

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands
to download the SSL certificates from Cloud Storage to the current directory.

```bash
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem .
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-cert.pem .
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-key.pem .
```

#### Configure the SSL certificates for use in Java on the Compute Engine VM instance

1. 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 <var translate="no">TRUST_CERT_KEYSTORE_PASSWD</var> with your own custom keystore password to be used to create the Java truststore.

```bash
keytool -importcert -alias MySQLCACert -file server-ca.pem \
-keystore quickstart-truststore -storepass TRUST_CERT_KEYSTORE_PASSWD
```
2. 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 <var translate="no">CLIENT_CERT_KEYSTORE_PASSWD</var> with your own custom client keystore password to be used to create the Java client keystore.
3. Convert the client key and certificate files to a PKCS #12 archive:

```bash
openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem \
-name "mysqlclient" -passout pass:CLIENT_CERT_KEYSTORE_PASSWD \
-out client-keystore.p12
```
4. Import the client key and certificate into a Java keystore:

```bash
keytool -importkeystore -srckeystore client-keystore.p12 -srcstoretype pkcs12 \
-srcstorepass CLIENT_CERT_KEYSTORE_PASSWD -destkeystore quickstart-keystore \
-deststoretype JKS -deststorepass CLIENT_CERT_KEYSTORE_PASSWD
```

#### 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:

- <var translate="no">INSTANCE_HOST</var> set to the **Private IP address** of your instance displayed on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

> [!NOTE]
> **Note:** Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. For Non-RFC 1918 address ranges, see [Learn about using private IP](https://docs.cloud.google.com/sql/docs/mysql/private-ip.md.txt#network_issues).

- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
export INSTANCE_HOST='INSTANCE_HOST'
export DB_PORT='3306'
export DB_NAME='quickstart_db'
export DB_USER='quickstart-user'
export DB_PASS='YOUR_DB_PASSWORD'
export TRUST_CERT_KEYSTORE_PATH='quickstart-truststore'
export TRUST_CERT_KEYSTORE_PASSWD='TRUST_CERT_KEYSTORE_PASSWD'
export CLIENT_CERT_KEYSTORE_PATH='quickstart-keystore'
export CLIENT_CERT_KEYSTORE_PASSWD='CLIENT_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.

```bash
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]
> **Note:** This quickstart step requires the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt), which provides command-line access to your Google Cloud resources using `gcloud CLI` commands. If you don't have the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) installed on your local computer, then [install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) to proceed.

1. 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`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/describe) command:

```bash
gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
```
2. 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.

   ```bash
   http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
   ```

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands
to download the SSL certificates from Cloud Storage to the `certs` directory.

```bash
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-cert.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-key.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:

- <var translate="no">INSTANCE_HOST</var> set to the **Private IP address** of your instance displayed on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

> [!NOTE]
> **Note:** Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. For Non-RFC 1918 address ranges, see [Learn about using private IP](https://docs.cloud.google.com/sql/docs/mysql/private-ip.md.txt#network_issues).

- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
export INSTANCE_HOST='INSTANCE_HOST'
export DB_PORT='3306'
export DB_NAME='quickstart_db'
export DB_USER='quickstart-user'
export DB_PASS='YOUR_DB_PASSWORD'
export DB_ROOT_CERT='certs/server-ca.pem'
export DB_CERT='certs/client-cert.pem'
export DB_KEY='certs/client-key.pem'
export PRIVATE_IP='TRUE'
```


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.

1. Install the Node.js packages necessary to run the app locally.

   ```bash
   npm install
   ```
2. Run the sample app.

   ```bash
   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]
> **Note:** This quickstart step requires the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt), which provides command-line access to your Google Cloud resources using `gcloud CLI` commands. If you don't have the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) installed on your local computer, then [install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) to proceed.

1. 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`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/instances/describe) command:

```bash
gcloud compute instances describe quickstart-vm-instance --format="value(networkInterfaces[0].accessConfigs[].natIP)"
```
2. 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.

   ```bash
   http://COMPUTE_ENGINE_VM_EXTERNAL_IP_ADDRESS:8080
   ```

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands
to download the SSL certificates from Cloud Storage to the `certs` directory.

```bash
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-cert.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-key.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:

- <var translate="no">INSTANCE_HOST</var> set to the **Private IP address** of your instance displayed on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

> [!NOTE]
> **Note:** Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. For Non-RFC 1918 address ranges, see [Learn about using private IP](https://docs.cloud.google.com/sql/docs/mysql/private-ip.md.txt#network_issues).

- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
export INSTANCE_HOST='INSTANCE_HOST'
export DB_PORT='3306'
export DB_NAME='quickstart_db'
export DB_USER='quickstart-user'
export DB_PASS='YOUR_DB_PASSWORD'
export DB_ROOT_CERT='certs/server-ca.pem'
export DB_CERT='certs/client-cert.pem'
export DB_KEY='certs/client-key.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.

1. Initialize a virtual environment and install the requirements to run to sample app.

   ```bash
   python3 -m venv env
   source env/bin/activate
   pip install -r requirements.txt
   ```
2. Run the sample app.

   ```bash
   python app.py
   ```


On your local computer set up [port forwarding over SSH](https://docs.cloud.google.com/solutions/connecting-securely.md.txt#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]
> **Note:** This quickstart step requires the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt), which provides command-line access to your Google Cloud resources using `gcloud CLI` commands. If you don't have the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) installed on your local computer, then [install the](https://docs.cloud.google.com/sdk/docs/install)[gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) to proceed.

1. In a terminal or in Powershell on your local computer, run the following [`gcloud compute ssh`](https://docs.cloud.google.com/sdk/gcloud/reference/compute/ssh) command to setup port forwarding over SSH. Before running the command, replace <var translate="no">YOUR_PROJECT_ID</var> with your project ID.

```bash
gcloud compute ssh quickstart-vm-instance --project=YOUR_PROJECT_ID --zone=us-central1-a --ssh-flag='-L 8000:127.0.0.1:8080'
```
2. 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.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. Click the `quickstart-instance` to see its **Overview** page
3. Click the **Connections** tab.
4. Under the **Security** section, click **Create client certificate**.
5. In the **Create a client certificate** dialog, enter `quickstart-key` as the name and click **Create**.
6. In the **New SSL certificate created** dialog,
   click each download link to download the certificates. Then, click
   **Close**.


   > [!WARNING]
   > **Important:** Store this private key securely. If you lose it, you must create a new client certificate.

   <br />

#### 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.

1. [Create a Cloud Storage bucket](https://console.cloud.google.com/storage/create-bucket).
   1. For **Name of your bucket** , enter the following name. Replace <var translate="no">YOUR_PROJECT_ID</var> with your project ID:

      ```bash
      YOUR_PROJECT_ID-quickstart-certs
      ```
   2. Click the **Create** button to create the bucket.
2. Click the **Upload Files** button to upload files to the newly created Cloud Storage bucket.
3. 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](https://docs.cloud.google.com/sdk/gcloud.md.txt)
will be used to upload the files.

1. Run the following [`gcloud storage buckets create`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/buckets/create.md.txt) command to make a new Cloud Storage bucket:

```bash
gcloud storage buckets create gs://YOUR_PROJECT_ID-quickstart-certs --location=us-central1
```
2. From the directory where you downloaded the certificates on your local computer, run the following [`gcloud storage cp`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands to copy the SSL certificates to the newly created Cloud Storage bucket:

```bash
gcloud storage cp server-ca.pem gs://YOUR_PROJECT_ID-quickstart-certs/
gcloud storage cp client-cert.pem gs://YOUR_PROJECT_ID-quickstart-certs/
gcloud storage cp client-key.pem gs://YOUR_PROJECT_ID-quickstart-certs/
```

### Go

#### 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`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands
to download the SSL certificates from Cloud Storage to the `certs` directory.

```bash
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-cert.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-key.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:

- <var translate="no">INSTANCE_HOST</var> set to the **Private IP address** of your instance displayed on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

> [!NOTE]
> **Note:** Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. For Non-RFC 1918 address ranges, see [Learn about using private IP](https://docs.cloud.google.com/sql/docs/mysql/private-ip.md.txt#network_issues).

- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
$env:INSTANCE_HOST="INSTANCE_HOST"
$env:DB_PORT="3306"
$env:DB_NAME="quickstart_db"
$env:DB_USER="quickstart-user"
$env:DB_PASS="YOUR_DB_PASSWORD"
$env:DB_ROOT_CERT="certs/server-ca.pem"
$env:DB_CERT="certs/client-cert.pem"
$env:DB_KEY="certs/client-key.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.

1. Get the dependencies required to run to sample app.

   ```bash
   go get ./...
   ```
2. Run the sample app.

   ```bash
   go run cmd\app\main.go
   ```
3. View the running sample app. Open a browser on the Compute Engine VM instance and go to `http://127.0.0.1:8080`.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands
to download the SSL certificates from Cloud Storage to the current directory.

```bash
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem .
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-cert.pem .
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-key.pem .
```

#### Configure the SSL certificates for use in Java on the Compute Engine VM instance

1. 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 <var translate="no">TRUST_CERT_KEYSTORE_PASSWD</var> with your own custom keystore password to be used to create the Java truststore.

```bash
keytool -importcert -alias MySQLCACert -file server-ca.pem `
-keystore quickstart-truststore -storepass TRUST_CERT_KEYSTORE_PASSWD
```
2. 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 <var translate="no">CLIENT_CERT_KEYSTORE_PASSWD</var> with your own custom client keystore password to be used to create the Java client keystore.
3. Convert the client key and certificate files to a PKCS #12 archive:

```bash
openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem `
-name "mysqlclient" -passout pass:CLIENT_CERT_KEYSTORE_PASSWD `
-out client-keystore.p12
```
4. Import the client key and certificate into a Java keystore:

```bash
keytool -importkeystore -srckeystore client-keystore.p12 -srcstoretype pkcs12 `
-srcstorepass CLIENT_CERT_KEYSTORE_PASSWD -destkeystore quickstart-keystore `
-deststoretype JKS -deststorepass CLIENT_CERT_KEYSTORE_PASSWD
```

#### 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:

- <var translate="no">INSTANCE_HOST</var> set to the **Private IP address** of your instance displayed on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

> [!NOTE]
> **Note:** Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. For Non-RFC 1918 address ranges, see [Learn about using private IP](https://docs.cloud.google.com/sql/docs/mysql/private-ip.md.txt#network_issues).

- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
$env:INSTANCE_HOST="INSTANCE_HOST"
$env:DB_PORT="3306"
$env:DB_NAME="quickstart_db"
$env:DB_USER="quickstart-user"
$env:DB_PASS="YOUR_DB_PASSWORD"
$env:TRUST_CERT_KEYSTORE_PATH="quickstart-truststore"
$env:TRUST_CERT_KEYSTORE_PASSWD="TRUST_CERT_KEYSTORE_PASSWD"
$env:CLIENT_CERT_KEYSTORE_PATH="quickstart-keystore"
$env:CLIENT_CERT_KEYSTORE_PASSWD="CLIENT_CERT_KEYSTORE_PASSWD"
$env:PRIVATE_IP="TRUE"
```

1.
   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.

   ```bash
   mvn jetty:run
   ```
2. View the running sample app. Open a browser on the Compute Engine VM instance and go to `http://127.0.0.1:8080`.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands
to download the SSL certificates from Cloud Storage to the `certs` directory.

```bash
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-cert.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-key.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:

- <var translate="no">INSTANCE_HOST</var> set to the **Private IP address** of your instance displayed on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

> [!NOTE]
> **Note:** Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. For Non-RFC 1918 address ranges, see [Learn about using private IP](https://docs.cloud.google.com/sql/docs/mysql/private-ip.md.txt#network_issues).

- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
$env:INSTANCE_HOST="INSTANCE_HOST"
$env:DB_PORT="3306"
$env:DB_NAME="quickstart_db"
$env:DB_USER="quickstart-user"
$env:DB_PASS="YOUR_DB_PASSWORD"
$env:DB_ROOT_CERT="certs/server-ca.pem"
$env:DB_CERT="certs/client-cert.pem"
$env:DB_KEY="certs/client-key.pem"
$env:PRIVATE_IP="TRUE"
```


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.

1. Install the Node.js packages necessary to run the app locally.

   ```bash
   npm install
   ```
2. Run the sample app.

   ```bash
   npm start
   ```
3. View the running sample app. Open a browser on the Compute Engine VM instance and go to `http://127.0.0.1:8080`.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> 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`](https://docs.cloud.google.com/sdk/gcloud/reference/storage/cp) commands
to download the SSL certificates from Cloud Storage to the `certs` directory.

```bash
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/server-ca.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-cert.pem certs/.
gcloud storage cp gs://YOUR_PROJECT_ID-quickstart-certs/client-key.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:

- <var translate="no">INSTANCE_HOST</var> set to the **Private IP address** of your instance displayed on the [Cloud SQL instances](https://console.cloud.google.com/sql) page in the Google Cloud console.

> [!NOTE]
> **Note:** Connections to a Cloud SQL instance using a private IP address are automatically authorized for RFC 1918 address ranges. For Non-RFC 1918 address ranges, see [Learn about using private IP](https://docs.cloud.google.com/sql/docs/mysql/private-ip.md.txt#network_issues).

- <var translate="no">YOUR_DB_PASSWORD</var> with the password of the `quickstart-user` that you created in the previous **Create a user** quickstart step.

```bash
$env:INSTANCE_HOST="INSTANCE_HOST"
$env:DB_PORT="3306"
$env:DB_NAME="quickstart_db"
$env:DB_USER="quickstart-user"
$env:DB_PASS="YOUR_DB_PASSWORD"
$env:DB_ROOT_CERT="certs/server-ca.pem"
$env:DB_CERT="certs/client-cert.pem"
$env:DB_KEY="certs/client-key.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.

1. Initialize a virtual environment and install the requirements to run to sample app.

   ```bash
   virtualenv --python python3 env
   .\env\Scripts\activate
   pip install -r requirements.txt
   ```
2. Run the sample app.

   ```bash
   python app.py
   ```
3. View the running sample app. Open a browser on the Compute Engine VM instance and go to `http://127.0.0.1:8080`.

   ![View deployed sample app](https://docs.cloud.google.com/static/sql/images/tabs-vs-spaces-app-screen-shot.png)


To stop the sample app, press <kbd>Control+C</kbd> in the Compute Engine
VM instance Powershell window where you started the sample app.

## Clean up


To avoid incurring charges to your Google Cloud account for
the resources used on this page, follow these steps.

### Delete Cloud SQL instance

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. Select the `quickstart-instance` instance to open the **Instance details** page.
3. In the icon bar at the top of the page, click **Delete**.
4. In the **Delete instance** dialog box, type `quickstart-instance`, and then click **Delete** to delete the instance.

### Delete Compute Engine VM instance

1. In the Google Cloud console, go to the **VM instances** page.

   [Go to VM instances](https://console.cloud.google.com/compute/instances)
2. Select the `quickstart-vm-instance` instance to open the **Instance details** page.
3. In the icon bar at the top of the page, click **Delete**.
4. Click **Delete** to delete the instance.

### Optional cleanup steps

If you're not using the **Cloud SQL client** role that you assigned to the
`Compute Engine default` service account, you can remove it.

1. In the Google Cloud console, go to the **Service accounts** page.

   [Go to IAM](https://console.cloud.google.com/iam-admin/iam)
2. Click the edit icon (which looks like a pencil) for the IAM account named **Compute Engine default service account**.
3. Delete the **Cloud SQL client** role.
4. Click **Save**.

If you're not using the API that was enabled as part of this quickstart, you
can disable it.

- API that was enabled within this quickstart:
  - Cloud SQL Admin API

1.

   In the Google Cloud console, go to the **APIs** page.

   [Go to APIs](https://console.cloud.google.com/apis)

   <br />

2. Select any API that you would like to disable and then click the **Disable API** button.

## What's next

Based on your needs, you can learn more about [creating Cloud SQL instances](https://docs.cloud.google.com/sql/docs/mysql/create-instance.md.txt).

<br />

You also can learn about creating [MySQL users](https://docs.cloud.google.com/sql/docs/mysql/create-manage-users.md.txt#creating)
and [databases](https://docs.cloud.google.com/sql/docs/mysql/create-manage-databases.md.txt#create) for your Cloud SQL instance.

For more information about pricing, see [Cloud SQL for MySQL pricing](https://cloud.google.com/sql/pricing).

Learn more about:

- Configuring your Cloud SQL instance with a [public IP](https://docs.cloud.google.com/sql/docs/mysql/configure-ip.md.txt) address.
- Configuring your Cloud SQL instance with a [private IP](https://docs.cloud.google.com/sql/docs/mysql/configure-private-ip) address.

Additionally, you can learn about connecting to a Cloud SQL instance from
other Google Cloud applications:

- [From an application running on App Engine standard environment](https://docs.cloud.google.com/sql/docs/mysql/connect-app-engine)
- [From an application running on Compute Engine](https://docs.cloud.google.com/sql/docs/mysql/connect-compute-engine.md.txt)
- [From an application running on GKE](https://docs.cloud.google.com/sql/docs/mysql/connect-kubernetes-engine.md.txt)
- [From Cloud Run](https://docs.cloud.google.com/sql/docs/mysql/connect-run.md.txt)