Creating and Deploying a Google Cloud SQL Database: A Visual Guide


Google Cloud is a powerful cloud platform that offers completely managed and scalable database solutions. Let’s look at how to set-up a database, calculate the monthly cost, and learn how to avoid common pitfalls for beginners.

What is a Cloud Database?

A Cloud Database is a database service stored and accessed remotely from remote servers (ie a cloud platform). Typically the database services will be accessed via a virtual machine or the admin console of the cloud service.

The largest three cloud service providers are Amazon Web Services (AWS), Microsoft Azure, and Google Cloud. Many tech companies and startups have moved towards cloud infrastructure for a few reasons. I also generally work in Let’s look at the advantages of using a Cloud Database.

Why is a Cloud Database advantageous?

The main advantages of Cloud infrastructure not only apply to web applications but also to database services and can be summarized in a few succinct points.

  • Cloud infrastructure is easily scalable up or down with little or no cost
  • Cloud infrastructure is replicated and backed up across many server centers
  • Cloud infrastructure can reduce initial startup costs substantially

These advantages alone are substantial and make cloud infrastructure a no-brainer for most startups and large tech companies.

Why use Google Cloud SQL?

Cloud services are not necessarily cheap.

Run continuously, a SQL database and virtual machine to access it run on minimal settings will cost around $50 a month with Google Cloud. AWS and Azure are slightly more expensive but are similarly priced. See the cost calculator to see how much damage you will incur using different services and settings.

How to set up and deploy a Google Cloud SQL database

1. Navigate to Google Cloud

To get started with creating a Cloud Console Project, first navigate to https://console.cloud.google.com. This will be the web address from where you will manage your cloud instance as an admin. Everything from adding additional users and adding permissions to writing CRON scripts is done here.

2. Sign in with a Google Account

You will be prompted to sign into an existing Google account or to create one. Do one of these options.

3. Agree to Terms of Service

4. Create a Cloud Console Project

First, select the “Select a Project” button on the top left of your screen. A popup will appear. Select the “New Project” button at the top right of the popup.

5. Navigate to the Cloud SQL Page

We want to use the Cloud SQL service. Find the “SQL” button on the left-hand navigation bar. Keep in mind that this navigation bar is collapsible so it might be hidden. If it is hidden select the button with three horizontal lines at the top left of your screen.

6. Create or Enable a Billing Account

Click “Crete Billing Account” on the bottom right and follow Google’s promps. There will be about 3 total screens and you will be required to input billing information.

Unfortunately, Cloud SQL is not free and you will need to enable a billing account. This process is pretty straightforward and just requires you to provide your credit card information or to link a payment service account such as Paypal.

Be careful though as Google Cloud is an enterprise service and can be extremely expensive. Google Cloud is a bit infamous for sending initial bills that are thousands of dollars because a beginner developer didn’t understand how to properly set up an instance.

Don’t be this person and continue to read carefully.

7. Click Create a Cloud SQL Instance

After enabling your billing account you should still be on the Cloud SQL page and see the following button. Click on “Create Instance”

8. Choose your SQL Dialect

Choose your SQL database type. For beginners and simple projects, I would say MySQL is fine. However PostgreSQL has some more advanced features available that can come in handy.

9. Select the minimal settings for deployment: Configuration

This is the page where you need to be careful. Refer to the table below for the recommended settings to use. DO NOT proceed with the default settings as selected by Google.

Now, this is where you need to pay careful attention. A mistake here could cost you lots of money so let’s take care to create our instance with the minimal settings.

WARNING: If you proceed with the default settings, Google Cloud will send you a bill for hundreds of dollars next month for just a single instance.

Please refer to the table below for the recommended settings. I didn’t include absolutely every setting in this table, but every setting that impacts performance or cost. If you use the recommended settings below and run your instance constantly, your bill at the end of the month will be around $50.

You can also turn your Cloud SQL instance off and on if there are periods of time when it doesn’t need to be in use. In this case, you could conceivably reduce your monthly bill to nearly nothing. Possibly around $5 depending on how much time you spend developing.

ConfigurationRecommended Setting
Zonal AvailabilitySingle Zone
Machine TypeLightweight – 1 vCPU, 3.75 GB
Storage TypeSSD
Storage Capacity10 GB
Enable Automatic Storage IncreasesUnchecked
ConnectionsPublic IP
Enable Point in Time RecoveryUnchecked
Automate BackupsChecked
Number of Backups4
These are the recommended settings to use to keep costs down during app development but maintain good performance and scalability later on. You will need to change the default settings. These settings will cost around $50 a month if the instance is run continuously.

10. Create Your New Cloud SQL Instance

Click the “Create Instance” button to officially create your new cloud SQL instance.

At the bottom of your new MySQL instance configuration page there is a button labeled “Create Instance”. Click this button to officially create your new instance.

Additional Questions

How do I get a refund from Google Cloud?

It is common for beginner Google Cloud users to accidentally receive a bill for an amount much higher than they were expecting. In this case, the emotions might range from shocked, angry, or even worried and you will be wanting some sort of refund.

Google Cloud Support will give a one-time bill adjustment if you request one with a compelling enough reason. This adjustment could range from 50%-70% off of a surprise bill. A billing adjustment from Google is a one-time adjustment so you will not be able to request it again. Ideally, being careful with the cloud service settings is the best bet to avoid needing to request a refund in the first place.

Google Cloud SQL charged me hundreds of dollars the first month I used it for something I didn’t use. The reason was that I didn’t properly research the billing costs and figured it would fall under the tempting $300 free credits they give you.

This was not the case.

I emailed them and received the following generic response:

Thank you for contacting us. This is regarding your Cloud SQL inquiry.

The GCP Tech Support team has provided the following guidance to assist you in understanding the common causes of an unexpected Cloud SQL instance charges.

Please check that you have properly secured your database by providing users and service accounts IAM roles and permissions that are needed for what each needs to accomplish. You should limit access to the database itself as much as possible. Self-hosted databases should have VPC firewall rules implemented to only allow ingress and egress to authorized hosts. All ports and endpoints not specifically required should be blocked. If possible, ensure changes to the firewall are logged and alerts are configured for unexpected changes using Stackdriver[1].

Ensure that you have automatic storage or binary logging features disabled. Only enable these features if you plan to continuously store large amounts of data or perform extensive data modifications such as continuous automated backups.
Automatic storage will check your available storage at 30 second intervals and if storage is insufficient, then more storage will be added to your instance. Storage size can be increased, but it cannot be decreased; storage increases are permanent for the life of the instance. With automatic storage enabled, a spike in storage requirements can result in permanently increased storage costs for your instance[2]. Binary logs use standard storage space instead of backup space, and are charged as storage[3].

Cloud SQL supports importing and exporting both compressed and uncompressed files. Compression can save significant storage space on Cloud Storage and reduce your storage costs, especially when you are exporting large instances. When you export a SQL dump or CSV file, use a .gz file extension to compress the data. When you import .gz files, it is decompressed automatically[4].

Please refer to the Cloud SQL pricing page for more information on how storage and network is charged[5]. If you have confirmed all of the above configuration for your Cloud SQL instances and you are still unsure of the charges, please let me know and I will proceed with further investigation with our GCP Tech Support team.

I hope this information helps. I will wait for your reply.

Thank you and have a great day ahead.

Regards,
Google Cloud Support

Luckily, if you are billed more than you think you should have been, Google Cloud will usually give a one-time bill adjustment. This took my $500 surprise bill down to about $180. Still this was more than I wanted to pay, but it was manageable. Just note that Google Cloud Support is very clear that this is a ONE-TIME adjustment.

And better yet just don’t make the same mistake as me in the first place.

How to estimate Google Cloud SQL monthly costs? Cloud SQL Pricing

This is your primary resource for estimating monthly costs with Google Cloud.

The Google Cloud Pricing Calculator is the go-to tool to estimate billing from various Google Cloud services. This is your primary source and is something you will need to spend time with.

Using this prioce calculator is quite intuitive and you only need to keep an extra tab open with your Cloud SQL configuration page to make sure the settings match on the calculator. Using the settings suggested in this article (as of Oct 2022), the monthly cost of a continuously running Cloud SQL instance will be around $50 a month with a small amount of variance. The variance will be due to the variance in month length.

Conclusion

Thanks for reading and look out for more content from RTL Coding. Hope this article was useful and if you would like to support this blog and this content feel free to donate via Paypal to help support more helpful content.

Sources

Source

Recent Posts