Creating Cloud SQL instance in GCP


Cloud SQL

Creating Cloud SQL Instance

Cloud SQL is a fully-managed database service that makes it easy to set up and use relational databases on Google Cloud Platform. This article covers the steps that will help in creating a MySQL 5 instance on Google Cloud Platform. It walks through the creation of a MySQL Instance, setting root password creating schema and a table.
We will create an MySQL instance named currencyproj and once it is created we will create a database and one table.
Prepare Instance
Create environment variables that will be used later in the lab for your project ID and the storage bucket that will contain your data
export PROJECT_ID=$(gcloud info --format='value(config.project)')
export BUCKET=${PROJECT_ID}-ml
Create a Cloud SQL instance
Create currencyproj MySQL instance : currencyproj
gcloud sql instances create currencyproj \
    --tier=db-n1-standard-1 --activation-policy=ALWAYS
Set Root Passord
following sets the password for currencyproj instance.
gcloud sql users set-password root --host % --instance currencyproj \
 --password Passw0rd
Create an environment variable with the IP address of the Cloud Shell
export ADDRESS=$(wget -qO - http://ipecho.net/plain)/32
White list the Cloud Shell
Whitelist the Cloud Shell instance for management access to your SQL instance
gcloud sql instances patch currencyproj --authorized-networks $ADDRESS
Get Cloud SQL IP Address
Get the IP address of your Cloud SQL instance by running
MYSQLIP=$(gcloud sql instances describe \
currencyproj --format="value(ipAddresses.ipAddress)")
Create the currency name table by logging into the mysql command line interface
mysql --host=$MYSQLIP --user=root \
      --password --verbose
Create DB and Table
After logging into the MySQL console, create database and table
create database if not exists currency_db;
use currency_db;


CREATE TABLE IF NOT EXISTS CURRENCY_NAME
(
  id varchar(255),
  title varchar(255),
  symbol varchar(255),
  PRIMARY KEY (ID)
);


Summary

We are able to create an instance of MySQL and then created a database and table.

No comments :

Post a Comment

Please leave your message queries or suggetions.