IM Week2 Lesson1
IM Week2 Lesson1
Databases are integral to modern computing, serving as organized collections of data that can be easily
accessed, managed, and updated. In this section, we'll explore the fundamentals of databases, focusing on
MySQL, one of the most popular database management systems (DBMS). By definition Database is simply a
structured collection of data.
What is MySQL
MySQL is an open-source relational database management system (RDBMS) that uses Structured Query
Language (SQL) to manage data. It's widely used for web applications and is known for its reliability, scalability,
and ease of use.
● MySQL got its name from the daughter of one of its co-founders, Monty Widenius, whose name is My.
Combining ‘My’ with ‘SQL,’ we get MySQL.
● MySQL is a durable database management system designed for managing relational databases. It is open-
source software supported by Oracle, meaning that you can use MySQL without any cost. Additionally,
you will have the flexibility to modify its source code to tailor it to your specific requirements.
● Despite being open-source software, you also have the option to purchase a commercial license from
Oracle, which provides access to premium support services.
● When compared to other database software like Oracle Database or Microsoft SQL Server, MySQL is
relatively easy to master.
● MySQL is versatile and can run on various platforms, including UNIX, Linux, and Windows. You can
install it on a server or even on a desktop. What’s more, MySQL is renowned for its reliability, scalability,
and speed.
The data within a database are naturally related, for example, a product belongs to a product category and
is associated with multiple tags. Hence, we use the term relational database.
In a relational database, we model data like products, categories, tags, etc., using tables. A table contains
columns and rows, much like a spreadsheet.
Tables can relate to one another table using various types of relationships, like one-to-one and one-to-
many.
Because we handle a substantial amount of data, we need a way to efficiently define databases, tables, and
process data. Moreover, we want to transform data into valuable information.
1. Data definition language (DDL) includes statements for defining the database and its objects such as
tables, views, triggers, stored procedures, etc.
2. Data manipulation language (DML) contains statements for updating and querying data.
3. Data control language (DCL) allows you to grant permissions to users to access specific data in the
database.
The Command Prompt is a command-line interpreter program available in Windows. The Command
Prompt program allows you to interact with the computer through text-based commands for tasks like running
programs, managing files, and configuring system settings.
If the bin directory is included in the PATH, you can use the mysql command from the Command Prompt without
the need to navigate to the bin directory.
On Windows, the PATH is an environment variable that contains a list of directories. Windows OS uses these
directories to locate executable files, making it easier to run applications from the Command Prompt without
specifying the full file path.
To connect to the MySQL Server, you type this command on Command Prompt:
mysql -u root -p
In this command:
-u root means that you connect to the MySQL Server using the user root.
-p instructs mysql to prompt for a password.
You type the password for the root user and press Enter:
Enter password: ********
If everything is OK, you will connect to the MySQL Server and see the following command:
mysql>
To display available databases in the current server, you enter the SHOW DATABASES statement terminated
by a semicolon (;) and press the Enter key:
show databases;
● First, the mysql command-line client sends the query to the MySQL Server.
● Second, the MySQL server executes the query and sends the result back.
● Third, the mysql command-line client displays the result.
Step 1
Download the classicmodels database attached on our google classroom.
Step 2
Unzip the downloaded file into a temporary directory. You can use any directory you prefer, for example, C:\temp
directory.
Step 3
Connect to the MySQL server using the mysql client program:
mysql -u root -p
In this command:
mysql: This is the command to start the MySQL client, which allows you to connect to interact with databases.
-u root: This specifies the user that you want to connect to the MySQL database server. In this case, it is the root
user that has full administrative privileges.
-p: This flag will prompt you to enter the password for the root user after you execute the command.
You’ll be asked to enter the password for the root user. Note that the password for the root user is the one that
you set when you installed MySQL.
Enter password: ********
After a successful login, you’ll see the prompt that looks like this:
mysql>
Step 4
Use the source command to load data into the MySQL Server:
source c:/temp/mysqlsampledatabase.sql
Step 5
Use the SHOW DATABASES command to list all databases in the current server:
show databases;
The output will look like the following including the newly created classicmodels database:
+----------------------------------+
| Database |
+----------------------------------+
| classicmodels |
| information_schema |
| mysql |
| performance_schema |
| sys |
+----------------------------------+
Data is information that has been collected and organized in a structured format. It can be numerical, text-
based, or images and is used to analyze patterns and trends, make decisions, and develop strategies. Data is a set
of values typically organized in a specific way. In most cases, data is collected into a table, with each row
representing a different data point and each column representing a separate data category. Data can answer
questions, solve problems, or provide information. Sometimes, data is used to make predictions or find trends.
And the data in a database can be divided into two main categories: static and dynamic.
● Static data is data that does not often change, such as a list of countries or products.
● Dynamic data is data that frequently changes, such as a list of customers or a list of orders.
What is DBMS?
A database management system (DBMS) allows users to store, retrieve, and manipulate data in a database.
A DBMS typically provides tools that enable users to create, update, and delete data in the database. In addition,
a DBMS may provide tools for managing the database, such as creating and deleting tables and indexes and
managing user access to the database. It also includes data security, data integrity, and data recovery features.
Types of DBMS
There are four main types of DBMS: relational, object-oriented, graph-based, and NoSQL.
● Relational DBMSs are the most common and use a tabular structure to store data.
● Object-oriented DBMSs use an object-oriented model to store data, and Graph-based DBMSs use a graph
structure to store data.
● NoSQL DBMSs are a newer DBMS type that uses a non-tabular structure to store data.
There are some other types of DBMS also considerable one, and there are,
● Hierarchical DBMS
● Network DBMS
● Cloud DBMS
● In-Memory DBMS
● Distributed DBMS
● Multivalue DBMS
● XML DBMS
Type of DBMS Description Examples
Relational DBMS A type of DBMS that organizes data into tables (also MySQL, Oracle, and
(RDBMS) known as relations) and allows for the creation of Microsoft SQL
relationships between them. Server
Object-oriented A type of DBMS that organizes data into objects and MongoDB and
DBMS allows for the creation of classes and inheritance. Apache Cassandra
(OODBMS)
Hierarchical A type of DBMS that organizes data into a tree-like IBM’s Information
DBMS (HDBMS) structure, with each record having a single parent and Management
zero or more children. System (IMS)
Network DBMS A type of DBMS that organizes data into a network- Integrated Data
(NDBMS) like structure, with multiple parents and children for Store (IDS)
each record.
NoSQL DBMS A type of DBMS that does not use the traditional MongoDB,
table-based structure of RDBMS. Instead, it uses a Cassandra, Redis
more flexible, document-based or key-value-based and Couchbase
data model.
Document- A type of NoSQL DBMS that organizes data into MongoDB and
oriented DBMS documents, similar to JSON or XML, and is often used Couchbase
for unstructured or semi-structured data.
Column-family A type of NoSQL DBMS that organizes data into Apache Hbase and
DBMS columns rather than rows, and is optimized for Google BigTable
handling large amounts of data.
Key-value A type of NoSQL DBMS that store data as a mapping Redis and Riak
databases of keys to values and are optimized for high-speed
data retrieval.
Graph DBMS A type of NoSQL DBMS that organizes data in the Neo4j and Amazon
form of nodes and edges, and is optimized for Neptune
handling relationships between data.
In-memory A type of DBMS that stores all data in the memory SAP HANA and
DBMS (RAM) rather than in disk storage. This allows for Apache Ignite
faster data access and is commonly used for real-time
data processing or high-performance computing.
Time-series A type of DBMS that is optimized for handling time- InfluxDB and
DBMS series data, which is data collected at regular intervals TimescaleDB
over time.
Benefits of DBMS
A database management system (DBMS) is a software package designed to define, manipulate, and
control a database. It is a system that enables the creation and maintenance of a central database. So, there are
plenty of benefits of this DBMS, and the following are the considerable ones,
● Data Integrity: A DBMS helps maintain data integrity due to its ability to enforce data integrity constraints.
This integrity ensures that data is consistent, accurate, and reliable over time.
● Data Security: A DBMS ensures data security through access control mechanisms like user profiles,
passwords, and other authentication methods. This security ensures that only authorized users have access
to the required data.
● Data Redundancy: A DBMS eliminates data redundancy by storing data in a single centralized location.
And this redundancy reduces the amount of data that needs to be stored and simplifies the data
manipulation process.
● Data Consistency: A DBMS ensures data consistency by enforcing data rules and constraints. More than
this, this consistency ensures that all users have access to the same up-to-date information.
● Cost Reduction: A DBMS system reduces the cost associated with data storage and data management.
What is RDBMS?
Generally, RDBMS stands for “relational database management system.” A relational database
management system (RDBMS) is a database management system (DBMS) that uses relational techniques for
storing and retrieving data. And also, it is based on the relational model, which organizes data into rows and
columns in tables.
RDBMS use SQL (Structured Query Language) to manipulate data in the database. SQL is a standard
language that most RDBMSs use and SQL can insert, update, delete, and query data in the database. RDBMSs
have been the most popular type of DBMS since the 1980s. And nowadays, RDBMS are the most widely used
database systems because they provide a powerful and flexible way to store, retrieve and manage data.
Features of RDBMS
One of the key features of an RDBMS is the use of a primary key and foreign keys to establish
relationships between tables. A primary key is a unique identifier for each record in a table, and a foreign key is
a reference to the primary key of another table. This allows for the creation of relationships between tables, such
as one-to-one, one-to-many, and many-to-many.
Examples of RDBMS
RDBMSs are widely used in many different industries, from small businesses to large enterprise systems.
Some popular examples of RDBMSs include MySQL, Oracle, and Microsoft SQL Server. They are well suited
for structured data and support SQL (Structured Query Language) which is a standard language for interacting
with relational databases.
RDBMSs provides a lot of functionality like ACID properties (Atomicity, Consistency, Isolation,
Durability), Indexing, backup, recovery, security and many more.
Examples of OODBMS
OODBMSs are well suited for handling complex, unstructured, or semi-structured data, and are often used
in applications such as engineering, geographic information systems, and multimedia. Some popular examples of
OODBMSs include MongoDB, Apache Cassandra, and ObjectDB. They are not as popular as RDBMSs but still
have their use cases.
However, OODBMSs are not as standardized as RDBMSs, and the query languages and interfaces used
to interact with them can vary widely between different systems. Additionally, OODBMSs generally have less
support for ad-hoc queries, reporting, and analysis than RDBMSs.
Examples of HDBMS
HDBMSs were popular in the past, especially for applications such as data modeling for manufacturing
systems and other similar applications. IBM’s Information Management System (IMS) is an example of a
HDBMS. However, they have largely been replaced by more modern DBMSs, such as RDBMSs and OODBMSs,
which provide more flexibility and scalability.
HDBMSs are not as popular as RDBMSs or OODBMSs and are not used as much as they used to be.
They are not suitable for large and complex data sets, and are not very good at handling many-to-many
relationships between records. They are best suited for highly structured data and applications that require a high
level of data integrity and security.
NoSQL DBMS
NoSQL (Not Only SQL) Database Management Systems (DBMS) refer to a type of DBMS that do not
use the traditional relational model and SQL (Structured Query Language) for data storage and retrieval. Instead,
they use alternative data models and query languages that are more suitable for handling large and unstructured
data sets, as well as for distributed and cloud-based environments.
NoSQL DBMSs are designed to handle big data and high-scale data processing workloads, they can handle
large volume, high velocity, and varied data. They are often used in web, mobile, gaming, and social media
applications, as well as in the Internet of Things (IoT), real-time analytics, and machine learning applications.
There are several different types of NoSQL databases. Some popular types of NoSQL databases include:
Document Database
Document databases, such as MongoDB and Couchbase, which store data in the form of documents and
allow for rich, nested data structures.
Column-Family Database
Column-family databases, such as Apache Cassandra and Hbase, which store data in the form of columns
rather than rows and are optimized for high read and write performance.
Key-Value Databases
Key-value databases, such as Redis and Riak, which store data as a mapping of keys to values and are
optimized for high-speed data retrieval.
Graph Databases
Graph databases, such as Neo4j and OrientDB, which store data as nodes and edges in a graph and are
optimized for traversing complex relationships.
NoSQL databases are more flexible and can handle unstructured data, which can be a great solution for
big data and real-time data-processing use cases. However, they lack the transactional guarantees and consistency
provided by RDBMSs and are not always suitable for complex queries, joins, and transactions.
In-memory DBMS
An In-memory Database Management System (DBMS) is a type of DBMS that stores all of its data in the
memory, as opposed to storing it on disk. This allows for faster data access and processing, since data does not
need to be read from disk and can be accessed directly from memory.
In-memory DBMSs are designed to handle real-time, high-concurrency, and high-throughput workloads.
They are often used in applications such as online transaction processing (OLTP), real-time analytics, and high-
frequency trading, where low latency and high performance are critical.
Benefits of RDBMS
A relational database management system (RDBMS) is a powerful tool for storing and retrieving data.
RDBMSs are used in various web-based applications, financial systems, and customer relationship management
(CRM) systems. RDBMSs are also well-suited for managing large volumes of data. RDBMS offer several benefits
over other database management systems.
● Structured Query Language (SQL): The most powerful benefit of RDBMS is the use of SQL to store,
retrieve, manipulate, and manage data. SQL is a powerful language that enables users to interact with the
database efficiently and effectively.
● Atomicity: This feature of RDBMS ensures that all the transactions in the system are completed in an
atomic manner. This means that all the transaction operations are done successfully, or none are done,
ensuring data integrity and consistency.
● Reliability: RDBMS provides a reliable system for storing, updating, and retrieving data. It also guarantees
data security since it maintains an audit trail of every transaction, which helps detect any anomalies in the
system.
● Scalability: RDBMS is highly scalable and can easily be expanded to accommodate larger datasets. And
this scalability leads to support for more users and data.
● Flexibility: RDBMSs offer a high degree of flexibility, allowing users to add, delete, and update data
easily.