How to get started with Cloud SQL for MySQL

Cloud SQL is an online managed database service that allows the administering of your relational databases on Google Cloud Platform. Databases offered in this platform are MySQL and PostgreSQL.

This how-to walks you how to create and connect to a Cloud SQL instance and perform basic SQL operations using the Google Cloud Platform Console and the MySQL client.

Overview

SQL queries perform tasks such as update records on a database or retrieve records from a database. Google Cloud offers MySQL as a cloud database.

Google Cloud SQL offers access to MySQL client through a cloud shell where you can run all MySQL queries and manage the database.

Ensure you Sign in to your Google Account, and in case you do not have one, sign up for a new account after logging in, Select or create a GCP project and make sure you enable billing for your project.

How to get started with Cloud SQL for MySQL

Create Cloud SQL instance

Select your project and click Continue.

Then, Click Create Instance as shown below;

Choose a database engine. Thus, Click MySQL.then click as shown below;

There are types of MSQL instances in our case we use Second Generation; then Click Choose Second Generation.

Enter a name for your  Instance ID. The choice is permanent and ensures you use lowercase letters, numbers and hyphens and always start with a letter.

Set a  root password and select the Region for your instance which should be the same region as the resources that access it.

Under Configuration options, update any other settings you need for your instance, Use the default values for the other fields. Click Create.

Connect to MySQL client using cloud Shell

Login to Google Cloud Platform Console, click on Cloud Shell  ()  to initialise Cloud Shell.

When Cloud Shell finishes initialising, you should see:

Click on the Cloud Shell prompt, type the below  command to connect to your Cloud SQL instance:

gcloud sql connect myinstance --user=root

My instance name is mysqlateam.  Replace this in the syntax;

gcloud sql connect mysqlateam --user=root

Type the root password to access MySQL shell;

Create a database and Insert records

Create MySQL database

CREATE DATABASE AteamTest;

Insert data into the Ateamtest database:

USE AteamTest;
CREATE TABLE entries (AteamTest VARCHAR(255), content VARCHAR(255),
    entryID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID));
    INSERT INTO entries (AteamTest, content) values ("Team Kenya", "Karibu Kenya");
    INSERT INTO entries (AteamTest, content) values ("Hakuna Matata", "Enjoy a Safari");

To view data from the database;

SELECT * FROM entries;

You should see:
+—————+—————-+———+
| AteamTest     | content | entryID |
+—————+—————-+———+
| Team Kenya    | Karibu Kenya |       1 |
| Hakuna Matata | Enjoy a Safari |       2 |
+—————+—————-+———+

2 rows in set (0.11 sec)

Clean up

If testing Cloud SQL, remember to delete the instance to avoid incurring charges from Google. For a production environment, check the pricing from here.

Navigate to Cloud SQL instance and select the instance you want to delete. On the far end, click on the three dots. Select Delete.

Conclusion

In this how-to, we have covered how to create a Cloud SQL instance that runs MySQL and created a database in which we inserted and retrieved records. Having set up this, you can now enjoy running MySQL queries and run your database with ease.

 

Check out these top 3 Cloud hosting services:

HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Hostinger
$1.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7

How to Install MySQL on a Windows Web Server Running Apache

This tutorial will show you how to install the MySQL database on a Windows serve
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How To Install MySQL on Windows

This how-to article teaches you how to install MySQL on Windows.
4 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to Move Your WordPress Site from Your Local Web Server to Your Live Site

You can always accelerate the development process by developing your WordPress s
4 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Disable MySQL 5 "Strict Mode" on an Ubuntu 18.04 VPS or Dedicated Server

How to Disable MySQL Strict Mode on MySQL 5.6 Running on an Ubuntu 18.04 VPS.
2 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top