Redeem and use your Google coupon. Do NOT enter your credit card. (If you have not received an email with the link to redeem a coupon, please see CS 4750's Announcement "Database server (and web server) options, and Google Cloud Platform coupon"). If more coupons are needed, please make a private post on Piazza. We will get you more coupons. Do NOT enter your credit card information.
This will prompt a screen allowing you to create a new project.
Enter your Project Name (e.g., cs4750db
),
be sure the Billing account is associated with
the Google coupon you redeemed. Then, click CREATE.
Note: depending on how your account was set, you may be required to enter Location or Organization. Please select University of Virginia and proceed to create the project.
Choose MySQL 8 for a database version.
For CS 4750, to minimize GCP service charge, select Enterprise, Sandbox environment.
Choose us-east4 for a region.
Select Single zone for availability.
indicates that the
SQL instance has been started.
indicates that the
SQL instance has not been started.
There are several ways to connect to a MySQL instance. In this quick introduction, we will use GCP cloud shell.
gcloud sql connect <your-instance-ID> --user=root --quiet
If this is the first time setting up the instance or using the cloud shell, you may be asked to authorize cloud shell.
If you receive a permission denied error, click the link specified in Cloud Shell to enable Cloud SQL Admin API.
Then, go to Cloud shell and
run gcloud sql connect <your-instance-ID> --user=root --quiet
to connect to the instance.
Let's create a guestbook database. To create a database, there are several options.
You may use the Create database feature of Google Cloud Console.
Once a database has been created, you should see a screen listing your database.
To delete a database, click the 3-dot and then delete.
You may run a SQL command to create a database.
CREATE DATABASE guestbook;
Note: SQL commands are not case sensitive. This example uses uppercase and lowercase simply to make it easy to read.
There are several ways to create a table. In this quick introduction, we will use GCP cloud shell.
USE guestbook; CREATE TABLE entries (guestName VARCHAR(255), content VARCHAR(255), entryID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID));
You may run DESC entries;
to view the table schema (structure).
There are several ways to insert data into a table. In this quick introduction, we will use GCP cloud shell.
USE guestbook;
Note: if you have previously specified the database, no need to include this code.
INSERT INTO entries (guestName, content) values ("Humpty", "Humpty's here!"); INSERT INTO entries (guestName, content) values ("Dumpty", "Dumpty's here too!");
There are several ways to retrieve data from a table. In this quick introduction, we will use GCP cloud shell.
USE guestbook;
Note: if you have previously specified the database, no need to include this code.
SELECT * FROM entries;
To disconnect from the mysql terminal (monitor), run the exit
command.
To disconnect from the Cloud Shell, run the exit
command.
CREATE DATABASE friendbook; USE friendbook; CREATE TABLE friends (friendName VARCHAR(255), phone VARCHAR(255), entryID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID)); INSERT INTO friends (friendName, phone) values ("Humpty", "111-111-1111"); INSERT INTO friends (friendName, phone) values ("Dumpty", "222-222-2222");
If you have not created a storage bucket, please refer to Create GCP storage bucket.
Upload friendbook.sql to your GCP bucket
You may need to click ">" to navigate to the desired file.
Assuming that your friendbook.sql file is in a bucket named cs4750db-demo.
Then click the Select button.
If you wish to execute a .sql on an existing database, select a destination database. Then, click Import.
To verify that your SQL file has been run successfully, connect to the instance using the Cloud Shell. Run the following code
USE friendbook; SELECT * from friends;You should see two records of data entered into your newly created friends table.
If you have not created a storage bucket, please refer to Create GCP storage bucket.
Assume the exported file will be called export-friendbook.sql and stored in cs4750db-demo bucket.
Click the Select button, and then Export.
To retrieve the exported file, go to your GCP console — Bucket details screen.
Go to GCP console, on the instance overview screen, click the STOP option.
Note: Remember to stop the SQL instance to avoid incurring charges.
Released under the
CC-BY-NC-SA 4.0 license.