Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Laboratory 1: Introduction to Relational.

Similar presentations


Presentation on theme: "Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Laboratory 1: Introduction to Relational."— Presentation transcript:

1 Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Laboratory 1: Introduction to Relational Databases and MySQL

2 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

3 Using Relational Databases and SQL Running MySQL (Console)

4 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.

5 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 ; Sets the current database for which you want to extract data from

6 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

7 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).

8 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).

9 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)

10 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.

11 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;

12 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

13 Using Relational Databases and SQL Running MySQL (MySQL QueryBrowser)

14 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.

15 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).

16 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

17 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

18 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

19 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

20 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)


Download ppt "Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Laboratory 1: Introduction to Relational."

Similar presentations


Ads by Google