Create Cloud SQL instance with gcloud sql
Prerequisites
GCP account
Open the Console.
Click on Activate Cloud Shell.
Accessing Cloud Shell:
Paste the below code.
$ export PROJECT_ID=$(gcloud info –format=’value(config.project) ‘)
It will export our project ID into $PROJECT_ID.
$ echo $PROJECT_ID
It will print our project ID
Running gcloud Command:
Authentication and Authorization:
$ export BUCKET=${PROJECT_ID}-ml
It will export the bucket name into $BUCKET
$ echo $BUCKET
It will print the bucket name
$ gcloud sql instances create taxi –tier=db-n1-standard-1
It will create a sql instance with name taxi.
It will take a little bit time to create.
Accessing the Instance:
$ gcloud sql users set-password root –host % –instance <sql_instance_name> –password <password>
To set password for SQL instance
$ gcloud sql instances patch <instance-name> –authorized-networks 0.0.0.0/0
Press y to continue.
Managing the Instance:
Open Console.
Menu > SQL
Copy the IP address.
$ MYSQL=<IP_ADDRESS>
$ echo $MYSQL
$ mysql –host=$MYSQL –user=root –password
Enter the password which you created. The password will not be visible. Press enter.
Here you can type your mysql codes.
$ show databases
It will list the databases.
$ exit
It will be exit from the mysql console .
press exit
This is all about Create Cloud SQL instance with gcloud sql