Databases I - 02 Logical Modeling, Docker
Databases I - 02 Logical Modeling, Docker
Relational data
model
Logical DB design
97
1
27/03/2025
Benefits: Disadvantages:
simplicity, software products that work in
no knowledge of the physical structure is conjunction with a relational data model
required, can be slow.
access to data is unlimited, depending on
the number of different accesses,
access to data is easy,
Multi-level data integrity is built in.
98
99
• is the set of admissible values for one or more attributes.
• N tuple:
• is a relation line representing a single record or providing data for a single
object (entity) of a closed organised world.
2
27/03/2025
101
3
27/03/2025
cell column
primary key foreign key
Faculty
name of the
ID name Description
table
1 FERI FERI is a renowned educational Cardinality
and research institution...
2 EPF The ETF offers a wide range of
study programmes at bachelor,
master and doctoral level.
102
degree of relation
Candidate Secondary
Primary
• Key:
• is an attribute or set of attributes that uniquely
specify a row within the table. Student
• primary ID enrolment_nr date_of_birth email fk_Faculty
• is that attribute or group of attributes 1 E9320376041 12.12.2001 [email protected] 1
within a table that will uniquely
2 E3107410974 15.3.2001 [email protected] 2
specify each row in the table.
• candidate
• is a key of which no real subset is a superset of the table key.
• composite / composite
• is a key consisting of more than one attribute.
• Secondary
• is a candidate key that has not been selected as the primary key. Faculty
• tuj (external) / foreign ID name Number_of_students
• is an attribute or group of attributes within a table that is the primary key
of another table (the source table). 1 FERI 3000
2 EPF 2000
103
4
27/03/2025
104
105
• The order of the rows in the table is irrelevant.
• Each table must have a primary key.
5
27/03/2025
• Entity integrity
• In a table, the primary key cannot have the value null.
• Referential integrity/integrity
• If there is a foreign (foreign) key in the relation, its value must
be identical to the value in its source table, or it must be null.
• The foreign key must not contain values that are not present
in the primary table.
106
E (A1, A2, ..., An) R (A1, A2, ..., An) Worker (ID, name, surname, date of
birth)
107
6
27/03/2025
7
27/03/2025
Relational DBMS
• A relational database is a type of database.
• It uses a structure that allows us to identify and access
data in relation to other pieces of data in the database.
Often the data in a relational database is organised into
tables.
• Relational DBMS is a program where you can create,
update, administer a relational database. Most
relational DBMSs use SQL to access the database.
111
8
27/03/2025
Graphical
interfaces for
working with the
MySQL
database
113
9
27/03/2025
114
115
10
27/03/2025
Docker - for
setting up
phpMyAdmin
& MySQL
Docker
• Installing Docker Desktop from https://www.docker.com/
• A new Docker folder somewhere on the disk (e.g. D:\Docker)
• Inside the folder, a new docker-compose.yml file
• YAML = human readable data serialisation language (used
for configuration files and in applications where data is
stored or transmitted)
• From the Docker Hub https://hub.docker.com/, find the tools
you need (e.g. php:apache, mysql, phpMyAdmin)
11
27/03/2025
12
27/03/2025
docker-compose.yml
services:
mysql:
container_name: mysql-pb # Container name, you can change it if you want, but it must be unique within the Docker environment
image: mysql:8.0.41 # Docker image downloaded from https://hub.docker.com/_/mysql. You can use the version as in this example
(8.0.41), or use 'latest' for the latest version
restart: unless-stopped # Allows the container to be restarted in case of an error, unless manually stopped by the user
environment:
- MYSQL_ROOT_PASSWORD=superVarnoGeslo # Set the password for the root user. It is recommended that this password is secure
and unique
volumes:
- ./data/mysql:/var/lib/mysql # Associates the local folder './data/mysql' with the MySQL data folder inside the container
to preserve data during restarts
port:
- "3306:3306" # Connects the internal port 3306 (default MySQL) to the external port 3306, allowing access to MySQL outside
the container (the port on the left side of the binary can be changed as desired)
phpmyadmin:
container_name: phpmyadmin-pb # Container name for phpMyAdmin. You can change it as you wish, but it must be unique within the
Docker environment
image: phpmyadmin/phpmyadmin:latest # Docker image for phpMyAdmin. 'latest' will download the latest version
restart: unless-stopped # Allows the container to be restarted in case of an error, unless manually stopped by the user
port:
- "8000:80" # Binds internal port 80 to external port 8000, allowing access to phpMyAdmin via a browser at
http://localhost:8000 (the port on the left side of the colon can be changed at will)
environment:
PMA_HOST: mysql-pb # Name of the MySQL container to which phpMyAdmin connects. This is the name of the MySQL container
('mysql-pb') used by Docker for networking between containers.
13
27/03/2025
• What's on the right side of the dock is always tied to the docker itself, and what's on the left side is tied to the local computer.
• A few commands
• # start (includes image downloads)
• docker compose up
• # off
• docker compose down
• #if we are just transmitting an image
• docker compose pull
• #if only updating
• docker compose up -d
• #when we download and run
• docker-compose pull && docker-compose up -d
Start
• Start the terminal in the folder where you have Docker and
docker-compose.yml file.
• Enter docker compose up for first boot and image download
14