Setting up SQL Cloud (MS SQL Server) on GCP
Cloud SQL instances on Google Cloud Platform is a fully managed relational data base service for databases like MySQL or PostgreSQL. Recently they have also added Microsoft SQL Server as a service.
There is a good read on the Google Cloud blog: Leave no database behind with Cloud SQL for SQL Server
This article is to help guide someone through setting up a instance of Cloud SQL with SQL Server, and to populate a database for testing.
Create Cloud SQL Instance
Navigate to Google Cloud Console
On the left side there will be 3 horizonatal lines, which we will refer to as the GCP Console, its the quick navigation to all the googles functionality.
In the GCP console, click SQL > VM Instances
Click create instance
We are choosing SQL Server, as it will be compatiable with our test data we want to load.
Click Choose SQL Server
We want to the below options to be input:
Backups can be enabled, if you want. However be mindful of the additional cost associated with it running. We have opted to have them turned off, as this will be a testing environment. We have the backup saved in the bucket, so we can restore it at any point in time, to restore the testing server.
If your going to access this server remotely (from local installation of SQL Server Management Studio — SSMS) then you will want a way to connect to it. You can either Add Network, under the authorised networks. Alternatively you can setup Cloud SQL Proxy. This is where you install the Proxy agent locally and it uses your google sign in crendentials, and it treats the server to be local installation.
Click on Create
This will take a while for it to deploy. Once it is completed you will see an active instance like below.
To get the connection infomation;
Click on the instance name, and you will see a section that says “Connect to this instance”
Loading Testing Data
In the GCP console, click Storage > Browser
Click create bucket
Once it is created, you want to Click on Cloud Shell
Stack Overflow releases its data masked to the public as open source. Because it is a production database, it is great to use to simulate examples or training excercises.
You can copy the data from the below public bucket, however it is setup for the requester to pay for the data transfer.
Your welcome download from various other sites, but it might require a bit more work.
https://dzone.com/articles/collection-sql-server-sample-databases
Create database
As the file is a .bak, we can create a database on our instance, then load the files directly in.
In the GCP console, click SQL
Click Overview
Click on Import
Then make sure “BAK” is selected, then select the database destination.
Now you have a MS SQL Server running on SQL Cloud, with Stack Overflow data.
Connecting to the database
If you have SQL Server Management Studio — SSMS installed locally, then you will be able to type in the connection details of the server.
The server details can be found by
In the GCP console, click SQL
Click Overview
You will see a window that says “Connect to this instance”
Locally you can type in this information, the defaul user will be sqlserver and the password setup when creating the DB.
If you do encounter any troubles connecting, make sure you have added a authorised network. If your really struggling to connect you can add the below to allow anyone to connect to your instance:
I wouldn’t recommend doing this long term, but it will enable to you connect to your instance.
Once connected you should see the below.