Download CS122_SUMMER_2009_LAB_01

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Serializability wikipedia , lookup

Microsoft Access wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

SQL wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

PL/SQL wikipedia , lookup

Concurrency control wikipedia , lookup

Database wikipedia , lookup

Versant Object Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
Using Relational Databases and SQL
Laboratory 1:
Introduction to Relational Databases and
MySQL
Steven Emory
Department of Computer Science
California State University, Los Angeles
Topics for Today
Lab #0
Make sure you all have NIS accounts
Make sure you all have CSNS accounts
Get MySQL installed onto your computer
Go over the Movie Archive Database
Homework #0
Get MySQL installed on your home computer
Become familiar with the Movie Archive Database
Using Relational Databases and SQL
Running MySQL
(Console)
Running MySQL
Start the database server
mysql-5.1.35/bin/mysqld.exe
Start the database client
mysql-5.1.35/bin/mysql.exe -u root
If you get an error, verify that the database server
(mysqld.exe) is running by checking the Task
Manager and looking for mysqld.exe in the list of
processes.
Simple MySQL Client Commands
All commands and queries should be terminated
by a semicolon
You don’t need these commands if using the
MySQL Query Browser
SHOW databases;
Displays a list of databases managed by the DBMS
USE <database name>;
Sets the current database for which you want to
extract data from
Creating the Movie Archive
Database
To create the Movie Archive database:
At mysql> prompt, type in:
CREATE DATABASE movie;
You should a message like:
Query OK, 1 rows affected (0.01 sec).
This command creates an empty database with no
tables
Loading the Movie Archive
Database
To load the Movie Archive database:
Place the movie.sql file from the CS122 Wiki page
into your mysql-5.1.35/bin directory
At mysql> prompt, type in:
USE movie;
SOURCE movie.sql;
You should see a bunch of messages like:
Query OK, 1 rows affected (0.01 sec).
Unloading the Movie Archive
Database
To unload the Movie Archive database:
Place the remove_movie.sql file from the CS122 Wiki
page into your mysql-5.1.35/bin directory
At mysql> prompt, type in:
USE movie;
SOURCE remove_movie.sql;
You should see a bunch of messages like:
Query OK, 1 rows affected (0.01 sec).
Deleting the Movie Archive
Database
To delete the Movie Archive database:
At the mysql prompt, type in:
DROP DATABASE movie;
You should get the following message:
Query OK, 0 rows affected (0.00 sec)
Displaying Table Names
To display a list of table names:
At the mysql prompt, type in:
SHOW TABLES;
You should get a list of table names.
Displaying Table Contents
To display the contents of a specific table:
At the mysql prompt, type in:
SELECT *
FROM tablename;
For example:
SELECT *
FROM Companies;
Console Tips
Use Notepad or Notepad++ to type your queries
and then paste into the command prompt
If the table has many attributes and each row is
rendered in MySQL on multiple lines, do the
following:
Command Prompt > System Menu > Preferences
Select the Layout tab
Change Screen Buffer Size parameters to:
Width: 1000
Height: 2400
Using Relational Databases and SQL
Running MySQL
(MySQL QueryBrowser)
MySQL Query Browser
An alternative MySQL client with a GUI
Download the zip (no installer) version of it from
the GUI Tools link in my syllabus.
Running MySQL
Start the database server
mysql-5.1.35/bin/mysqld.exe
Start the query browser
MySQL GUI Tools 5.0/MySQLQueryBrowser.exe
Server Host: localhost
Port: 3306
Username: root
Password: (leave this empty, unless you change it)
Click on OK, then Ignore (if necessary).
Creating the Movie Archive
Database
To create the Movie Archive database:
Right-click in the Schemata window and choose:
Create New Schema
Type in movie and press OK
Loading the Movie Archive
Database
To load the Movie Archive database:
Double-click on movie in the Schemata window to
make it current (the name of the current database will
be bold)
Choose File > New Script Tab
Click on the Load button on the toolbar
Choose movie.sql and press Open
Click on the Execute button on the toolbar
We are now ready to run queries
Unloading the Movie Archive
Database
To unload the Movie Archive database:
Double-click on movie in the Schemata window to
make it current (the name of the current database will
be bold)
Choose File > New Script Tab
Click on the Load button on the toolbar
Choose remove_movie.sql and press Open
Click on the Execute button on the toolbar
Deleting the Movie Archive
Database
To delete the Movie Archive database:
In the Schemata window, right-click on the movie
database and choose Drop Schema
Displaying Table Contents
To display the contents of a specific table:
In the Schemata window, double-click on a table
name and then press Execute (the green lightning bolt
button on the main toolbar)