Getting Started with mysql
Before you begin your second project assignment, you will need to
get your database set up. The instructions to accomplish that follow:
- Log in to napa.
- Type mysql -u yourUserName
-p. You will be prompted for a password. At this point,
your password is the same as your username.
- Type use yourUserName;. Each of you has your own
database with a name the same as your username. This command
will allow you to access and start using that database.
- Now, you will need to create the three tables you will use for
your project assignment. The first table contains a list of
entries for each student. The second table contains a list of
entries for each course offered. The third table contains a
list of registration entries. Each entry has a student id and a
course id. An entry indicates that the given student is
registered in the given course. To create the student table
type:
create table student (firstname VARCHAR(20),
lastname VARCHAR(20), password VARCHAR(20), STUID INT NOT NULL
PRIMARY KEY);
To create the second table type:
create table course (department VARCHAR(20), number INT,
title VARCHAR(20), COURSEID VARCHAR(20));
To create the
third table type:
create table reg_entry (STUID INT,
COURSEID VARCHAR(20));
- Next, you will need to insert values into your database.
You can do that by hand using the following command as an
example:
insert into student (firstname, lastname,
password, STUID) values ('Mickey', 'Mouse', 'mickeypw',
12347);
You can also create a text file and load the
values into the database. The command to load a text file
is:
LOAD DATA local INFILE "student.txt" into table
student fields terminated by ':';
This assumes that you
have a text file name students.txt in the directory where you
were when you typed mysql. The format of the students file
should be as follows:
Sami:Rollins:samipw:12345:
Mickey:Mouse:mickeypw:12346:
Notice that the command
specified that ':' is the field delimiter.
You should be ready to start connecting from within Java. More
mysql documentation can be found at: http://www.mysql.com/doc/en/
and https://napa.mtholyoke.edu/localdoc/mysql/.
Sami Rollins