0% found this document useful (0 votes)
4 views22 pages

Week 1

The document is a lab manual for database systems focusing on MySQL installation and configuration, creating and managing databases, and understanding database schemas. It outlines step-by-step instructions for installing MySQL, creating a 'Northwind' database, restoring its schema, populating it with data, and generating scripts for database structures. The manual serves as a practical guide for users to learn fundamental database management skills.

Uploaded by

yasirasad341
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views22 pages

Week 1

The document is a lab manual for database systems focusing on MySQL installation and configuration, creating and managing databases, and understanding database schemas. It outlines step-by-step instructions for installing MySQL, creating a 'Northwind' database, restoring its schema, populating it with data, and generating scripts for database structures. The manual serves as a practical guide for users to learn fundamental database management skills.

Uploaded by

yasirasad341
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Database Systems

Lab Manual 1

Learning Objectives:
1. Install and configure the MySQL server to prepare a
working environment for database development and
management.
2. Create a new database named "Northwind" to understand the
basic process of setting up a database.
3. Restore database schema by executing scripts (e.g.,
northwind.sql) to comprehend how schema scripts define
database structure.
4. Populate the database with data using northwind_data.sql to
practice importing data into a structured database.
5. Create a new database to practice the fundamental steps of
setting up a database environment for structured data storage
and management
6. .Generate scripts for a database schema to understand how
database structures (e.g., tables, constraints) are defined and
exported.

LO1: Installation and Configuration of MySQL


Step 1: Download MySQL Installer
1. Open your browser and go to:
https://dev.mysql.com/downloads/installer/
2. Select the larger installer (not the web installer) with the full
setup.
o Example: mysql-installer-community-x.x.x.msi.

Database Systems-Manual 1 Page | 1


3. Click Download and then "No thanks, just start my download"
to proceed without creating an account.

Database Systems-Manual 1 Page | 2


Step 2: Launch the Installer
1. Navigate to your Downloads folder and double-click the
downloaded file to start the installation.
2. If prompted by Windows User Account Control, click Yes to
allow the installer to run.
Step 3: Select Setup Type
1. On the Setup Type screen:
o Choose Full (recommended for a complete installation
with all features).
2. Click Next.

Step 4: Install Required Components


1. On the Check Requirements screen, ensure all required
components are listed.
2. Click Execute to download and install the required components.
o If a license agreement pops up, click I Agree.
3. Wait for the process to complete, and then click Next.

Database Systems-Manual 1 Page | 3


Step 5: Configuration
1. On the Product Configuration screen, click Next.

2. Type and Networking:


o Leave the default settings (e.g., Development Computer).
o Click Next.

Database Systems-Manual 1 Page | 4


Step 6: Authentication Method
1. On the Authentication Method screen:
o Select "Use Strong Password Encryption for
Authentication (Recommended)".
2. Click Next.

Step 7: Set Root Password


1. On the Accounts and Roles screen:
o Enter a strong password for the root user.
▪ Example: Choose a mix of uppercase, lowercase,
numbers, and symbols.
o Important: Save this password securely, as it will be
required for accessing the database.
2. Click Next

Database Systems-Manual 1 Page | 5


Step 8: Service Configuration
1. Leave the Windows Service Configuration settings as default.
o MySQL will automatically start as a service on system
boot.
2. Click Next.

Step 9: Apply Configuration


1. On the Apply Configuration screen, click Execute to apply all
settings.
2. Wait for the configuration process to complete.
3. Once completed, click Finish.

Step 10: Test Server Connection


1. On the Connect to Server screen:
o Enter the root username and the password you set earlier.
2. Click Check to verify the connection.
o If successful, you’ll see a confirmation message.
3. Click Next.
Database Systems-Manual 1 Page | 6
Step 11: Finish Installation
1. On the final screen, click Finish to complete the installation.
2. If a MySQL console appears, you can close it.

Post-Installation Steps
1. Open MySQL Workbench or any MySQL-compatible client to
connect to your server.
2. Use the credentials (root and your password) to log in and begin
creating databases or executing SQL queries.

LO2: Create a new database named "Northwind" to


understand the basic process of setting up a database.
Step 1: Open MySQL Workbench
1. Launch MySQL Workbench from the Start Menu or desktop.
2. Under the "MySQL Connections" section:

Database Systems-Manual 1 Page | 7


o Click on your database connection (e.g., Local Instance
MySQL).
o Enter your root password (set during installation) if
prompted.

Step 2: Create a New Database


1. Once connected, navigate to the top menu and click on "File" >
"New Query Tab" (or press Ctrl+T).
2. In the query editor window, type the following SQL command:
CREATE DATABASE Northwind;
3. Click on the "Execute" button (lightning bolt icon) or press
Ctrl+Enter to run the command.
Step 3: Verify the Database Creation
1. On the left-hand Schema Browser pane, right-click and select
"Refresh All".
2. Look for the Northwind database in the list of schemas.
Step 4: Set Northwind as the Active Database
1. To ensure you're working with the Northwind database, execute
the following command:
USE Northwind;
2. Click on the "Execute" button to set Northwind as the current
database.
Step 5: Confirm the Database Exists
1. Run the following command to list all databases in your MySQL
instance:
SHOW DATABASES;
2. Verify that Northwind appears in the list of databases.
Additional Notes
• The Northwind database is now created, but it does not yet
contain any tables or data. You will populate it later using the
provided northwind.sql and northwind_data.sql scripts.
• If you encounter errors, ensure you are logged in with a user
account that has privileges to create databases.
Database Systems-Manual 1 Page | 8
LO3: Restore database schema by executing to
comprehend how schema scripts define database structure.
Step 1: Download the Database Scripts
1. Download the northwind.sql file from https://shorturl.at/wUFhw
and store in a location to access later.
Step 2: Select the Target Database
1. In the left-hand Schemas pane:
o Right-click on the Northwind database.
o Select "Set as Default Schema" to ensure that all
operations target this database.
Step 3: Open the Schema Script
1. In the top menu, click on File > Open SQL Script.
2. Navigate to the folder containing northwind.sql.
3. Select the northwind.sql file and click Open.
Step 4: Review the Schema Script
1. The contents of the northwind.sql script will appear in the query
editor.
2. Review the script to understand its structure:
o CREATE TABLE statements define the tables.
o ALTER TABLE statements define relationships and
constraints.
Step 5: Execute the Schema Script
1. Click on the "Execute" button (lightning bolt icon) in the toolbar
or press Ctrl+Shift+Enter.
2. Monitor the Action Output pane at the bottom:
o Look for messages indicating successful execution (e.g.,
Table Created).
Step 6: Verify the Schema Restoration
1. Refresh the Schemas pane by right-clicking and selecting
"Refresh All".
2. Expand the Northwind database to view the restored structure:
o Check the Tables, Views, and Stored Procedures folders.
3. Run the following query to list the tables in the database:
Database Systems-Manual 1 Page | 9
Show TABLES;
Step 7: Resolve Errors (If Any)
1. If you encounter errors:
o Check for missing privileges or syntax errors.
o Ensure the Northwind database exists and is set as the
default schema.
2. Common command to use if permissions are missing:
GRANT ALL PRIVILEGES ON Northwind.* TO 'root
@'localhost';
Step 9: Test the Schema
1. Verify that the schema is functional by running the following
query to describe one of the tables (e.g., Customers):
DESCRIBE Customers;
2. Confirm that all columns, data types, and constraints are
correctly defined.

LO4: Populate the database with data to practice


importing data into a structured database.
Step 1: Download the data scripts
1. Download the northwind_data.sql file from
https://shorturl.at/aKOBQ and store in a location to access later.
Step 2: Select the Target Database
1. In the left-hand Schemas pane:
o Right-click on the Northwind database.
o Select "Set as Default Schema" to ensure that the data is
imported into the correct database.
Step 3: Open the Data Script
1. In the top menu, click on File > Open SQL Script.
2. Navigate to the folder containing the northwind_data.sql file.
3. Select the northwind_data.sql file and click Open.
Step 4: Review the Data Script
1. The contents of the northwind_data.sql script will appear in the
query editor.
2. Review the script to understand its structure:

Database Systems-Manual 1 Page | 10


o Look for INSERT INTO statements, which populate the
tables with data.
Step 5: Execute the Data Script
1. Click on the "Execute" button (lightning bolt icon) in the toolbar
or press Ctrl+Shift+Enter.
2. Monitor the Action Output pane at the bottom:
o Look for messages indicating successful execution (e.g.,
Rows Inserted).
Step 6: Verify Data Population
1. Refresh the Schemas pane by right-clicking and selecting
"Refresh All".
2. Expand the Tables folder under the Northwind database.
3. Test the data population by running a SELECT query for one of
the tables. For example, to check the Customers table:
SELECT * FROM Customers;
4. Review the output to ensure the table is populated with data.

LO5: Create a new database to practice the fundamental


steps of setting up a database environment for structured
data storage and management
Step 1: Create a New Database
1. Open MySQL Workbench:
o Launch MySQL Workbench and connect to your
MySQL server (e.g., Local Instance MySQL).
o Enter your root password if prompted.
2. Go to the "Schemas" Pane:
o Locate the Schemas section on the left-hand side.

Database Systems-Manual 1 Page | 11


3. Create a New Database:
o Right-click anywhere in the Schemas pane and select
"Create Schema...".
o A new window titled "Create Schema" will appear.

4. Provide the Database Name:


o In the Name field, enter the name of the database (e.g.,
spikodb1).
o Leave other settings (Character Set and Collation) as
default.

Database Systems-Manual 1 Page | 12


5. Click "Apply":
o Review the automatically generated SQL script (e.g.,
CREATE DATABASE spikodb1;).
o Click Apply to execute the script.

6. Confirm Database Creation:


o Check for the success message and click Finish.
o Refresh the Schemas pane to see the new database
(spikodb1).

Database Systems-Manual 1 Page | 13


Step 2: Create a Table
1. Set the Default Schema:
o Right-click on the newly created database (spikodb1) in
the Schemas pane and select "Set as Default Schema".
2. Open the Table Creation Wizard:
o Expand the spikodb1 database in the Schemas pane.
o Right-click on the Tables folder and select "Create
Table...".

3. Define the Table Structure:


o Table Name: Enter Product in the Table Name field.
o Add columns by filling out the grid:
▪ Column Name: ProductID
▪ Data Type: INT
▪ Check PK (Primary Key), NN (Not Null),
and AI (Auto Increment).
▪ Column Name: ProductName
▪ Data Type: VARCHAR(100)
▪ Check NN (Not Null).
▪ Column Name: Price
▪ Data Type: DECIMAL(10,2)
▪ Check NN (Not Null).
▪ Column Name: Quantity
▪ Data Type: INT
▪ Check NN (Not Null).

Database Systems-Manual 1 Page | 14


4. Click "Apply":
o Review the SQL script (e.g., CREATE TABLE
Product...).
o Click Apply to execute the script.

5. Confirm Table Creation:


o Check for the success message and click Finish.
o Expand the Tables folder in spikodb1 to see the Product
table.

Step 3: Insert Data into the Table


1. Open the Table Editor:
o In the Schemas pane, expand the Tables folder under
spikodb1.
o Right-click on the Product table and select "Select Rows
- Limit 1000".
2. Switch to Edit Mode:
o In the result grid, click the Edit (pencil icon) at the
bottom-right corner.
3. Enter Data:
o Add rows directly into the table by filling out the grid:
▪ ProductName: Laptop, Price: 1000.00,
Quantity: 10

Database Systems-Manual 1 Page | 15


▪ ProductName: Smartphone, Price: 500.00,
Quantity: 20
▪ ProductName: Headphones, Price: 50.00,
Quantity: 50
▪ ProductName: Keyboard, Price: 25.00,
Quantity: 30
▪ ProductName: Mouse, Price: 15.00, Quantity:
40

4. Apply Changes:
o Click Apply to save the data into the database.
o Confirm the SQL INSERT statements in the wizard and
click Apply.
5. Verify the Data:
o Refresh the data grid to ensure the rows are successfully
added.
Step 4: Verify the Table and Data
1. Check Table Data:
o Right-click on the Product table and select "Select Rows
- Limit 1000" to view the inserted data.
2. Output Example:
ProductID ProductName Price Quantity
1 Laptop 1000.00 10
2 Smartphone 500.00 20
3 Headphones 50.00 50
4 Keyboard 25.00 30
5 Mouse 15.00 40

Database Systems-Manual 1 Page | 16


LO6: Generate scripts for a database schema to
understand how database structures (e.g., tables,
constraints) are defined and exported.

Step 1: Open MySQL Workbench


1. Launch MySQL Workbench.
2. Connect to your MySQL server:
o Select your connection (e.g., Local Instance MySQL).
o Enter your root password (if prompted).

Step 2: Select the Target Schema


1. In the left-hand Schemas pane:
o Locate the database schema you want to export (e.g.,
my_db).
o Right-click on the my_db schema.
o Select "Schema Export" or proceed to the next step to
use the Dump tool.

Database Systems-Manual 1 Page | 17


Step 3: Open the Data Export Tool
1. Go to the top menu and click Server > Data Export.
2. In the Data Export window:
o Select the schema you want to generate scripts for (e.g.,
Northwind).

Step 4: Configure Export Settings


1. Choose Export Options:
o Check the box for "Export to Self-Contained File".
o Specify the file path where the script will be saved (e.g.,
C:\Database_Scripts\my_db.sql).
2. Export Type:
o Under Objects to Export, select:
▪ Dump Structure Only to export only the schema
(tables, constraints, etc.).
o Leave Data Export unchecked if you do not want the
data.

Database Systems-Manual 1 Page | 18


Step 5: Export the Schema
1. Click Start Export.
2. Monitor the Progress Log at the bottom of the window:
o Ensure that the export completes successfully without
errors.

Step 6: Verify the Generated Script


1. Navigate to the file path where the schema script was saved.
2. Open the script file (e.g., my_db.sql) in a text editor or IDE
(e.g., Notepad++, Visual Studio Code).
3. Review the contents:
o Look for CREATE TABLE statements defining the
structure of tables.
o Check for ALTER TABLE statements defining
relationships, indexes, and constraints.

Database Systems-Manual 1 Page | 19


Lab Tasks
Part 1:
1. Create a new database named TestDB_2024_CS_X
2. Create a new table named student using 5 to 6 attributes
3. Generate Scripts of your database
4. Restore your schema to another machine
5. Generate scripts of data
6. Restore data to other system as well

Part 2:
Task 1: Connect to the Northwind Database
• Objective: Ensure the database connection is set up properly.
• Steps:
1. Open MySQL Workbench.
2. Connect to your MySQL server by selecting your connection
(e.g., Local Instance MySQL).
3. Verify that the Northwind database is visible in the Schemas
pane.
Task 2: List All Tables
• Objective: Identify the tables in the Northwind database.
• Steps:
1. Expand the Northwind schema in the Schemas pane.
2. Note down the names of all tables (e.g., Customers, Orders,
Products, etc.).
3. Output Example:
Tables in Northwind:
- Customers
- Orders
- Products
- Employees
- Categories

Task 3: View Table Structures


• Objective: Understand the columns and data types in key tables.
Database Systems-Manual 1 Page | 20
• Steps:
1. Right-click on a table (e.g., Customers) in the Schemas pane.
2. Select "Table Inspector" or "View Table Details".
3. Note the column names, data types, and constraints (e.g.,
primary keys).
Task 4: Record Key Details
• Objective: Document the structure of a few key tables.
• Example for Customers:
Column Name Data Type Key/Constraint
CustomerID VARCHAR(5) Primary Key
CompanyName VARCHAR(40) Not Null
ContactName VARCHAR(30) -
Country VARCHAR(15) -

Task 5: Browse Data


• Objective: View a sample of the data stored in each table.
• Steps:
1. Right-click on a table (e.g., Customers) in the Schemas pane.
2. Select "Select Rows - Limit 1000" to view the data.
3. Review the first few rows of data to understand the type of
information stored.
Task 6: Document Examples
• Objective: Record a few rows of data from key tables for reference.
• Example for Customers:
CustomerID CompanyName ContactName Country
ALFKI Alfreds Futterkiste Maria Anders Germany
ANATR Ana Trujillo Emparedados y Ana Trujillo Mexico
helados
Task 7: Review Table Relationships
• Objective: Understand how tables are related without using queries.
• Steps:
1. In MySQL Workbench, reverse engineer the schema (if
available).
▪ Database > Reverse Engineer.
2. Review the Entity-Relationship (ER) diagram for the
Northwind database.
Database Systems-Manual 1 Page | 21
3. Note key relationships between tables:
▪ Example: Orders table references Customers via the
CustomerID column.
4. Document simple relationships:
▪ Example:
▪ Orders.CustomerID →
Customers.CustomerID (Foreign Key).
Task 8: Prepare a Lab Report
• Objective: Summarize findings in a concise report.
• Content to Include:
1. List of Tables: Document all tables in the database.
2. Table Structures: Provide column details for 2-3 key tables.
3. Sample Data: Include a few rows of data from each table.
4. Relationships: Highlight primary relationships between
tables.

Database Systems-Manual 1 Page | 22

You might also like