Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
56 views

MySQL Practical 1

The document provides instructions for installing XAMPP, which includes Apache, MySQL, PHP, and phpMyAdmin. It then explains how to use phpMyAdmin to create a School database and two tables (Lecturer and Course) within it. Steps are provided to populate the tables with sample data and define a foreign key relationship between the tables. The document concludes by describing how to control database access by setting a password for the default root user.

Uploaded by

crybert zinyama
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

MySQL Practical 1

The document provides instructions for installing XAMPP, which includes Apache, MySQL, PHP, and phpMyAdmin. It then explains how to use phpMyAdmin to create a School database and two tables (Lecturer and Course) within it. Steps are provided to populate the tables with sample data and define a foreign key relationship between the tables. The document concludes by describing how to control database access by setting a password for the default root user.

Uploaded by

crybert zinyama
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Practical 1 - MySQL INSTALLATION

MySQL Installation Instructions


Download and install XAMPP from the link https://sourceforge.net/projects/xampp/

 The XAMPP stack of software is an open-source local host server that provides a number
of functionalities through the package of software it contains. 
 The Apache web server, MySQL, PHP, Perl, FTP server, and phpMyAdmin are all
included in the XAMPP package. 
 The XAMPP Control Panel can be used to start and stop the MySQL package.
 The XAMPP Control Panel can be used to test and modify projects before launching
them on the internet. 

AbouphpMyAdmin
 phpMyAdmin is an open-source piece of software that lets you run and manage MySQL
over the Internet.
 You can create a MySQL database using phpMyAdmin, which is a graphic user interface
(GUI) written in the Hypertext Preprocessor (PHP) programming language.
 It provides web-based MySQL administration services, i.e., creating, retrieving, updating,
deleting, indexing, etc.

Steps to Create MySQL Database Using XAMPP


1. Launch the XAMPP control panel by clicking the icon . You can now start or stop
any module.
2. Click the Start button corresponding to the Apache and MySQL modules to see
figure 1.

Figure 1: The XAMPP Control Panel

Page 1 of 8
3. Click the Admin button corresponding to the MySQL module. You are automatically
directed to a web browser to the following address http://localhost/phpmyadmin

4. A number of tabs are displayed (figure 2), click on the Database tab.

Figure 2:Tabs

5. See the Create option displayed (figure 3); select an appropriate name for the input
field titled Database name. Keep in mind when selecting the name for the database
are:

 The number of characters used should not exceed 64.


 The name should comprise of letters, numbers and underscore.
 The database name should not start with a number.
 It should be relevant to the topic for which it is being created

Figure 3: Create Database

6. Fill in the form (figure 3) by typing the database name “School” and click Create.
Make sure the database is successfully created.

Steps to Create MySQL tables


 MySQL database consists of a collection of logically interrelated structured tables.
 Tables store information in a logical manner
 The School database is empty, we, therefore, create two tables Lecturer and Course
into the database by using the following steps
7. In the School database, click on the Structure tab. You will see a Create Table option
(figure 4). Fill the input fields titled Name and Number of Columns. In the Name filed type
“Lecturer” and in the Number of Columns field type “2” to create Lecturer table shown by
table 1.
8. Then Click the Go button (Figure 4)

Page 2 of 8
Figure 4: Create Table

9. Next step is to set columns based on their types. Type the names for each column,
select the type and maximum length allowed for the input field. Set LNum column as
the primary key column (Figure 5).
 A primary key value is unique. It is used to uniquely identify rows in a table

Figure 5: Field Types

 You can view the SQL script generated by clicking the button Preview SQL.
10. Next Click the SAVE button to get Figure 6. Figure 6 shows the structure of the
Lecturer table.

Figure 6

Page 3 of 8
11. The next step is to fill in (populate) the Lecturer table. Use the table 1 to insert
records in the lecturer table.
Table 1
Lecturer
LNu LName
m
0001 Moyo
0210 Kufa
0010 Dube
1009 Mhizha

12. Click the Insert tab next to the search button

13. Type the number of rows that you want to insert. The Lecturer table has four rows

14. Fill in the fields as shown table 7 and press Go button

Figure 7

15. To view the Lecturer table, click the Browse tab you get figure 8

Page 4 of 8
Figure 8

16. Now let us create the Course table with the following information. Remember the
Course table is contained in the School database. CNum is the primary key whilst
LNum is a foreign key. A foreign key links logically related tables. It exits in both
tables Lecturer and Course. Click School on the phpMyAdmin to create a new table
as shown in figure 9

Figure 9

17. Create new table Course with three columns fill in table see figure 10

Page 5 of 8
Figure 10

18. Next step is to set columns based on their types. Type the names for each column,
select the type and maximum length allowed for the input field. The CNum column is
the primary key column. The values of LNum in Course table must always match
with values of LNum in Lecturer table to avoid data inconsistences. Table 2 is the
Course table
Table 2
Course
CNum CName LNum
CUIT20 Database 0210
1
CUIT21 Operations 0210
0
CUIT40 Micros 1009
1
CUIT11 ITCA 0001
2

How to Specify Foreign Key


19. Next step is to apply the foreign key constraint to CNum column. Click the Relation
View tab (figure 11) on the table structure for Course

Figure 11

20. Assign foreign key constraints. Fill in the fields as indicated in figure 12 and click the
Save button

Page 6 of 8
Figure 12

 RESTRICT option prevents the removal (i.e. using delete) or modification


(i..e using an update) of rows from the parent table. It means that any
attempt to delete and/or update the parent will fail throwing an error.
 No Action There will not be any change in the referencing rows when
the referenced ones are deleted or updated. Same as restrict
 Cascade option
 Delete: the referencing rows will be deleted automatically along
with the referenced ones.
 Problem need to keep history
 CASCADE if the parent primary key is changed, the child value
will also change to reflect that.
 SET NULL. On Delete/Update the value of referencing record will be set
to NULL automatically along with the referenced ones.
21. Use the information provided in table 2 to insert records in the Course table.
Remember the Lnum values in the Course table should match the values in the
Lecturer table otherwise input a null value. (Referential integrity constraint)

22. Click Browse to view your table

Figure 13: Course Table

Page 7 of 8
Controlling Access
A database needs is secured by limiting the number of users that are allowed to modify and read the
data. A password can be set. In terms of default settings, the host's username is "root" and there is
no password provided. Follow the given steps to increase the privacy of the database:

1. Click the Server icon at the top of the page, then click on the "User Accounts" tab at the
top of the page

2.  Press "Edit Privileges" under "Actions" option corresponding the Username=


"root" and Hostname = "localhost"

3. Click on the tab 'Change password' and type your password in the provided field. Retype the
password to confirm it and then finally click on the "Go." Now the password has been set.

Page 8 of 8

You might also like