Creating Database
Once our SQL instance is ready, let’s create a Database. Navigate to all instances and then select the database instance you have created and scroll down to find Open Cloud Shell.
Wait for few seconds until the terminal opens up. You will find a pre-written command is there for you to connect your database to the Cloud shell. Press ENTER and give your instance’s password.
After sometime MySQL prompt will open and you can execute MySQL quires.
To learn about MySQL Quires check this article on mysql-common-mysql-queries.
To create a new Database in MySQL execute the following query
CREATE DATABASE guestbook;
This will create a new database named “guestbook” in cloud sql.
Now using the same database create a new table and insert two rows of data. Let’s name our table as “entries” and columns as “guestName”, “content”, and “entryID”. We will make “entryID” as the primary key for the table.
/* Using the guestbook database*/
USE guestbook;
/*Create table */
CREATE TABLE entries (guestName VARCHAR(255), content VARCHAR(255),
entryID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID));
/*Insert Data*/
INSERT INTO entries (guestName, content) values ("first guest", "I got here!");
INSERT INTO entries (guestName, content) values ("second guest", "Me too!");
Let’s check the table we have just created. Execute the following query to see the table.
SELECT * FROM entries;
As you can see 2 rows are there in the table with the data we have inserted.
How to Use Cloud SQL to Create and Manage Relational Databases
Data is everywhere, and managing data is a challenge. Most web websites and applications, businesses, and organizations use databases to store their data. while everything is moving online in a rapid manner managing databases becomes a challenge for organizations. Google Cloud Platform solves all major Relational database problems by introducing their Cloud SQL. Cloud SQL supports all major RDBMS and provides migration from offline databases. In this article, we will learn how businesses can use Cloud SQL to create databases and manage Relational Databases and use their most of time on business logic rather than investing in managing Databases.
Contact Us