In this article, we will learn How to create MySQL Database and use gcloud CLI to create databases, tables, and run queries on database objects.
A few Articles, which I already wrote and might be helpful for you if you are beginning with Google Cloud Platform are:
Let’s Begin:
Step 1: Log in with Google Cloud Platform by visiting https://console.cloud.google.com/ (Google provides $300 as a free trial, but for that, you need to link your credit card).
Once logged in you will be redirected to Google Cloud Dashboard as shown in the below image.
Step 2: You can view the menu list of Google Cloud Products and Services by clicking on the Navigation menu on the left side as highlighted. Go to the SQL menu option as shown in the below image.
Step 3: Click on Create Instance button as shown in the below image.
Select the database engine for which you want to create the instance. I am selecting MySQL for demonstration.
Provide the Instance Id, Password, Database engine, Region, and zonal availability while creating the new MySQL Instance.
Select the zonal availability and click on the Create Instance button.
Step 4: You will see the instance id with the green tick icon once the instance is ready.
Now open the google cloud shell by clicking on the Cloud shell icon in the top right corner as shown in the below image.
Run the below command in gcloud CLI to connect with MySQL Instance with the root user.
You will see a dialog for Authorizing Cloud Shell. Click on the Authorize button and provide the credential which was passed during the MySQL Instance creation.
You will see that MySQL is connected with a command-line shell.
Step 5: Let’s try to create a database using the “
create database <DB_NAME>” command.
Switch to the database using the “
use <DB_Name>” query.
Let’s add a table named Users in the MySQL Database created in the above steps.
Insert sample data in the table using the Insert command as shown below.
Now run the Select query to view the records inserted in the table.
You can also create the database from the Google Cloud Platform User Interface by clicking on the Database menu option as shown in the below image. Users can also be created by clicking on the users’ menu and providing the access details like restricting the host by IP Address or address range.
I hope this article will help you in creating and working with the MySQL database.
Thanks
0 comments:
Post a Comment