Using Google Cloud SQL with App Engine

I explore using Google Cloud SQL.

Create DB

Visit SQL section.

/posts/gcp/using_google_cloud_sql_with_app_engine/001_sql.png

Select MYSQL.

/posts/gcp/using_google_cloud_sql_with_app_engine/002_sql.png

Enabling Compute Engine API.

/posts/gcp/using_google_cloud_sql_with_app_engine/003_sql.png

I selecting MySQL 8.0 region same as App Engine region. This is test DB, thefore setting lowest instance resources.

/posts/gcp/using_google_cloud_sql_with_app_engine/004_sql.png

New project MySQL instance created.

/posts/gcp/using_google_cloud_sql_with_app_engine/005_sql.png

Creating test_database database

/posts/gcp/using_google_cloud_sql_with_app_engine/006_sql.png

Connect to the DB

Connect to the db via DBeaver. By default, all external IP addresses are blocked from reaching your Cloud SQL instance.

Find out your IP address

Add your IP to Authorized networks.

/posts/gcp/using_google_cloud_sql_with_app_engine/007_sql.png

Let’s test DB connection.

/posts/gcp/using_google_cloud_sql_with_app_engine/008_sql.png

By default, Cloud SQL allows unencrypted connections from authorized networks. This is not good, as it allows traffic to be intercepted, possibly leading to a data breach.

Recommend you use the Cloud SQL SQL proxy to connect DBeaver to Cloud SQL.

Install SQL proxy on linux 64bit:

1
2
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
chmod +x cloud_sql_proxy

In order to run the proxy we need to get the instance name from the developer console. Go to the Cloud SQL instance page and click the instance name to open its Instance details page.

/posts/gcp/using_google_cloud_sql_with_app_engine/010_sql.png

Start the proxy in its own terminal so you can monitor its output. Replace <INSTANCE_CONNECTION_NAME> with the instance connection name you copied in the previous step. Replace .

1
./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:<PORT>

/posts/gcp/using_google_cloud_sql_with_app_engine/009_sql.png

Testm Cloud SQL proxy connection.

/posts/gcp/using_google_cloud_sql_with_app_engine/011_sql.png

Then you can click the Test Connection button and you should see.

/posts/gcp/using_google_cloud_sql_with_app_engine/012_sql.png

Conncection via Cloud SQL Proxy successfull. Now I can enable Allow only SSL connections and restart service.

/posts/gcp/using_google_cloud_sql_with_app_engine/013_sql.png

As expected, unsecure conection is failing, althougt connection via proxy work fine.

/posts/gcp/using_google_cloud_sql_with_app_engine/014_sql.png