Open In App

How to Create a MySQL Database with Cloud SQL on Google Cloud Platform?

Last Updated : 20 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The collection of all the data used for the proper functioning of our product is called a need database (DB) and the system that manages the DB is called a need Database Management System(DBMS).

Why Data Management Is Essential?

We know that in any startup or business or product based companies like Flipkart, Amazon, Facebook, Google, or Microsoft, in any tech platform or any clothing brand, or suppose even in restaurants, etc Data storing and managing have become an integral part of proper functioning of the company. We know that without storing data no profit can be calculated or the next strategies for promoting a certain product or application cannot be planned by the marketing team or the sales team. Even social media apps, any online retailer shops, and basically every product in this world need users for its use because if the product is not of anyone’s need, it is useless. So for the products to thrive we need our required form of data. So we can also say for making any product usable among a mass amount of people we need chunks and chunks of data about the users going to use it and if it is any retailing app even data about the products to be sold are required, depending on the purpose the type of data differs.

What is SQL?

SQL is called Structured Query Language. Now from the full form, the first thing we can understand is that this is a Programming Language like Java, Python, C++, etc. This is a structured programming language like C. This language is used to generate a query and get our desired Tasks done over the data stored in RDBMS(RELATIONAL DATABASE MANAGEMENT SYSTEM). RDBMS is a kind of database where data is stored and managed in a structured table form just like how data is stored in Excel sheets. Suppose we went into any shop or mall, apart from the owner we also see people working under the owner for selling us our products, asking us our requirements, and basically performing the task we are commanding them. So, consider the shop as the database here, the products inside the shop as data, and the person dealing with customers as the SQL.  SQL acts as a communicator between humans and the database itself. Like any other programming language, SQL has certain commands for performing insertion, deletion, manipulation & updation of data in DB.

What is MySQL?

MySql is a popular and standard RDBMS used for storing, retrieving, and manipulating data. MySQL is known for its speed, reliability, and user-friendly environment. If you want to know about MySQL in detail you can refer to MySQL – Introduction for more.

What is GCP Cloud SQL?

Cloud computing is a very popular domain/field nowadays since we know all the companies including startup or multimillionaire businesses use cloud for storing their RDBMS. Earlier back in time we used to store databases in our computer system and managing them also used to be a quite hectic work but as time progressed the concept of cloud became popular. In cloud we are provided with large amounts of memory depending on the amount we pay to the companies that are providing us the cloud services.For example nowadays we use google photos , google drive, etc where we upload our data to save up our device’s space and backup facilities including maintaining facilities are also provided. So cloud reduces our effort and time. Google cloud (GCP) is also such a cloud computing platform provided by google which provides us with various tools for our projects, one of them is SQL. This means you can create databases using SQL as per your utility purpose or deploy clusters and web applications without maintaining it yourself in your own hardware as google cloud will take care of it for which you are also paying that platform and they provide you with many more facilities which you will know if you study about GCP in detail.

  • An AppSheet plan that supports database connections.
  • Access to a Google Cloud Platform account i.e You should already have an existing google cloud account or create it for using GCP. You can sign up for a free trial that includes $300 in credit to use on GCP services.
  • Database Instance – The database instance is the structure that manages a collection of database files. An instance can hold several databases. In the tutorial below, you will generate a public IP address to connect with the database instance.
  •  Schema – In this context, schema and database are referring to the same thing. It is a collection of data made up of several tables. Schema is the term used in MySQL Workbench. Database is the term used in Google Cloud and AppSheet.

Steps To Create A MySQL DB With Cloud SQL ?

Step 1: Open your Google cloud Account

Step 2: In the Google Cloud Console, on the Navigation menu , click Databases > SQL.(encircled in red)

GCP Console

Step 3: Click create instance then If you see 3 database engines such as MySQL, PostgreSQL & SQLserver, choose MySQL.

MYSQL Engine

Step 4: Fill up the space of Instance ID(an ID given to the database instance for identification that you are going to create) as per your choice. Read the rules that are mentioned above the box for maintaining them while giving your instance ID.Then set a root password of your choice else if you don’t know any you can also click the GENERATE option but don’t forget to copy it as for accessing your DB you will need it in the future . It is necessary for protecting your database from getting tampered.

MYSQL Instance

Step 5: Select the presents from the dropdown as your preferred criteria

SQL Instance
Step 6:
Then choose the region which you find suitable for the best performance of your application , if the region is set by default for recommendation leave it unchanged.  

Region and Avalibility Zone

Step 7: Click Show configuration options to expand the configuration options, if you want to configure your database else leave it as default.

Step 8: Under the Connectivity section ensure that Public IP box is checked. By checking this box, Google Cloud will create an IP address that you can use to connect your AppSheet account to the database instance.Then Click Add network. 

Public Network

Step 9: Then scroll down at the end of the page see CREATE option click that and wait until instance is created

Step 10: When you see the green tick as shown in the encircled part of the picture, this indicates that you MySQL instance is ready

Step 11: Click the Cloud Shell   icon in the upper right corner.Click Continue.

Step 12: Enter the command used for letting the cloud shell connect your MySQL instance. In the picture below in place of myinstance you will enter your SQL instance name that you created earlier 

Command to Run

Step 13: Then you will get the authorization notification,for that click AUTHOIZE .

Azure Shell
The output will be like the below picture on the cloud shell screen. Enter the password that you generated or entered of your choice so that your instance can be accessed by the cloud shell. 

But after entering the password the place where you entered it will appear black making you think whether it is some glitch or not but no worries passwords aren’t visible on the cloud shell screen 

Step 14: Now something like this will appear.

MySQL

Step 15:
Now as you have got access to your instance you will enter  the following commands through MySQL for making database and storing data, even for manipulating databases. First let us create a database by entering the command from the below picture in the cloud shell.

Create Data base  
here in place of
guestbook you will give the name you want to give to your database or as you are instructed to.

Step 16: The output will be similar to the picture below

Query
Step 17:  
This means that you are inserting data into the database . Texts In bracket are the entries made into the database you created in the earlier step.So the texts within the bracket are of your own choice , depending on what entry you want to make in the RDBMS.

Insert
Step 18:
Enter the commands excluding the texts in bracket of the below picture.   The texts within brackets are the data, but the data varies from project to project so the data will be of your own , don’t copy them blindly.

Use Guestbook

CREATE TABLE means creating a table with entries of the text in brackets, CONTENT means what the content will be , INSERT means inserting the data. All these are a part of SQL Commands which you need to learn.

Output:

Output

Now exit the cloud shell and got to the left pane of the MySQL page, click DATABASE to view the database that you created.

FAQs On MySQL DB With Cloud SQL

1. Is Cloud SQL Same As MySQL?

The MySQL features offered by a Cloud SQL instance are identical to those offered by a locally hosted MySQL instance.

2. Can I Run MySQL In Cloud?

Yes you can create Create a Cloud SQL for MySQL instance. 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads