MySQL Practical 1
MySQL Practical 1
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.
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:
6. Fill in the form (figure 3) by typing the database name “School” and click Create.
Make sure the database is successfully created.
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
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
13. Type the number of rows that you want to insert. The Lecturer table has four rows
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
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
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
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