Read Chapter 1 and sections 2.1, 2.2, and 2.3 of Chapter 2. This should not be taxing, as it is mostly nontechnical.
The purpose of the rest of this assignment is to get you to install and start using MySQL on your computer by working through an online tutorial. You will use MySQL throughout the course. (When I have taught this course previously, we used a centralized Oracle SQL server on the lab machines, which required people to log into the lab machine first, then the oracle server remotely. MySQL has the advantage of running on your own machine, so you can take it with you. You'll need about 0.5 Gb of space to install it, though.)
Before reading further, please note: The rest of this handout has been tested on a Mac OS system. I have not used any of the MS Windows operating systems for over a decade, and I currently have no device running any Microsoft OS. I imagine you can get MySQL running on such a system, but I personally can be of little or no help for you to do it. The TA is much more likely to be able to help you if you need it.
MySQL is a client-server application, even if the client and server are running on the same machine. When you run a MySQL session, you are actually interacting with a client program mysql on your local machine, which then sends commands and retrieves data from the MySQL server (started automatically at system start-up or by invoking mysqld from the shell prompt). Your MySQL sessions will involve simple scrolling text only. You may use a GUI if you want, but it is not required, and I won't be able to answer GUI-related questions.
I'm going to assume that you have never used MySQL before. One way to install MySQL, the one I recommend, is to go to https://www.mysql.com, click the Downloads tab, and follow the links to download and install the MySQL Community Edition (GPL), MySQL Community Server (the latest version is 8.0). Select your platform (I use MacOS for my Macbook). I chose the DMG archive and all the default configuration options, including having the MySQL server start up at system start-up. Your milage may vary. For security, you should choose a good root password and REMEMBER IT!!! You won't need it that often, but sometimes you'll have to do some administrative stuff and you'll need root privileges for that. Also, if you ever forget your regular user password, you can reset it while logged in as root (see below for how to do this). If you ever forget your root password, however, I don't know of any way to recover short of reinstalling MySQL from scratch. (That's not a total disaster for this class, because all entered data will come from stored external files.) Having a root password is actually optional, but strongly recommended for security.
An alternative way to install MySQL is to follow the (somewhat dated) instructions here, but for a Mac this requires also installing Homebrew, so I didn't do it.
The goal of this exercise is to work through the tutorial on the MySQL website, a link to which is given later in this handout. You will only need to work up through Section 3.3.4.5, Date Calculations (so you may stop before Section 3.3.4.6, Working with NULL Values). (You can certainly go further if you wish, and that'll put you ahead on the learning curve.) This tutorial already assumes a working MySQL system and running server, however, and you are not there yet. Here is what you have to do first to get MySQL so that you can run the tutorial. This should work pretty much the same for any unix/linux/MacOS-like system, and I will assume you are using such a system and that the server is running on the same machine you are using as the client (e.g., your laptop). As I mentioned above, I don't know about MS Windows other than what is absolutely necessary for my job. I'm sure this will all work on Windows with the right modifications.
Don't forget the final semicolon. If you accidentally hit the return key before the semicolon, no problem; just put the semicolon on the next line and hit the return key again. For more information about this command, click here.
You are now ready to start the tutorial, using your regular (i.e., non-root) MySQL user account. Go to https://dev.mysql.com/doc/refman/8.0/en/tutorial.html. There are a few discrepancies between the tutorial and what you will experience on your system. Note the following anomalies as you go through the tutorial:
To see the contents of the pet table at any time, type
mysql> SELECT * FROM pet;
Suppose you make a mistake. For example, if you run the SOURCE pet.sql
command more than once, you'll put duplicate entries into your table.
You can empty out the table using
mysql> DELETE FROM pet;
then repopulate it with the SOURCE command again. (Be careful
with the DELETE command!)
If you ever forget your regular user password for mysql, you can reset
it by logging in as root and giving the following command:
ALTER USER 'steve'@'localhost' IDENTIFIED BY 'some_new_password';
Of course, use your own user name instead of "steve".
After going through the tutorial up through Section 3.3.4.5, your
pet table should have nine (9) rows, and the
SELECT * FROM pet; command should return this:
+----------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+--------+---------+------+------------+------------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
| Puffball | Diane | hamster | f | 1999-03-30 | NULL |
+----------+--------+---------+------+------------+------------+
Make sure that this is what your table contains.
Outside of mysql, edit a new text file called hw1.sql with the following four SQL statements in order, each terminated by a semicolon:
mysql -p menagerie
and enter your user password when prompted (this will work on
unix/linux/Mac systems; for Windows, YMMV). Including the database
name on the command line automatically loads
it, so you do not need to issue a "USE menagerie" command inside mysql.
Inside mysql, type
mysql> tee hw1.log
mysql> source hw1.sql
mysql> notee
mysql> quit
The first command tells mysql to append everything subsequently appearing in the
session to the file hw1.log, until the notee command is given,
which stops logging. The source command reads the hw1.sql file
and runs its commands in order as if you had typed them at the prompt.
You should make a .zip file hw1.zip containing both hw1.sql and hw1.log files. Upload your .zip file electronically using CSE Dropbox. You should submit your assignment to Section 001 regardless of which of these sections you are in.