Introduction to
SQL for Data
Analysis
Presented by: Martin Omollo
What you will learn
This training aims to get you started with SQL
• Install MySQL RDBMS
• Create a Database
• Selecting & Retrieving Data with SQL
• Use SQL commands to filter, sort, and summarize
data.
• Modifying and Analyzing Data with SQL
Database
What is Data?
In simple words, data can be facts related to any object
in consideration. For example, your name, age, height,
weight, etc. are some data related to you. A picture,
image, file, pdf, etc. can also be considered data.
What is Database?
A database is a systematic collection of data. They
support electronic storage and manipulation of data.
Databases make data management easy.
Database Management
System
Database Management System (DBMS) is a collection of programs that
enable its users to access databases, manipulate data, report, and represent
data. It also helps to control access to the database.
Relational databases
This type of database defines database relationships in the form of tables. It is
also called Relational DBMS, which is the most popular DBMS type in the
market. Database example of the RDBMS system include MySQL, Oracle, and
Microsoft SQL Server database.
What is SQL
SQL is the standard language for dealing with Relational Databases.
SQL is used to insert, search, update, and delete database records.
Out of all the relational databases, MySQL remains the most popular database
for organizations.
Relational Database Concepts
Before we dive into SQL, there are a few relational database (RDBMS) concepts that will set the background for you.
Schema
The database schema refers to the organization of data. It is a blueprint of how the database is constructed. In RDBMS, the database model is implemented by
the schema. It is the Entity-relationship model.
Table
One of the main units of the schema is the table. In RDBMS, tables are laid out and associated with each other in different types of relationships (one to one, one
to many, many to many) relationships.
Columns
The vertical partitions of tables are called columns. In RDBMS, a column is often also called an attribute.
Rows
The horizontal partitions of tables are called rows. In RDBMS, a row is often also called a tuple.
Indexes
In RDBMS, the index is a data structure that improves the operation of the table by quickly locating the data.
-
SQL Statements
SQL is the Structured Query Language for
RDBMS databases. When you retrieve
data, you typically use SQL statements to
retrieve the data. You can join tables
together to select out just the right types of
data from different purposes using SQL
statements.
MySQL
MySQL is an open source relational
database.
MySQL is cross platform which
means it runs on a number of
different platforms such as
Windows, Linux, and Mac OS etc.
Why MySQL
Who Uses MySQL
• Huge websites like Facebook, Twitter, Airbnb, Booking.com, Uber, GitHub,
YouTube, etc.
• Content Management Systems like WordPress, Drupal, Joomla!, Contao, etc.
Why MySQL?
• Open Source - MySQL is open-source software. You don’t have to spend a single
penny to access its services.
• Cross-Platform - MySQL can run on Windows, Linux, Unix, and other operating
systems.
• High Availability - MySQL possesses a high processing system that makes MySQL
process bulk queries and transactions while ensuring unique memory caches.
• Reliability - SSH and SSL provide secure connections in MySQL. MySQL comes
with features such as data encryption and data backup for recovery.
1. Open the MySQL website on a browser.
Installing MySQL 2. Select the Downloads option.
Use MySQL
Installer
•3. Select MySQL Installer for Windows.
4. Choose the desired installer
and click on download.
5. After the download, open
the installer.
6. It will ask for permission; when it does, click Yes. The installer will then open. Now, it will ask
to choose the setup type. Here, select Custom.
7. Click on Next. With this, you will install MySQL server, MySQL Workbench, and MySQL shell.
8. Open MySQL Servers, select the server you want to install, and move it to the Products/Features to be
installed window section. Now, expand Applications, choose MySQL Workbench and MySQL shell. Move
both of them to ‘Products/Features to be installed’.
9. Click on the Next button. Now, click on the Execute button to download and install the MySQL server,
MySQL Workbench, and the MySQL shell.
10. Once the product is ready to configure, click on Next. Under Type and Networking, go with the default
settings and select Next.
11. For authentication, use the recommended strong password encryption.
12. Set your MySQL Root password and click on next.
13. Go for the default windows service settings and
under apply configuration, click on execute. Once the
configuration is complete, click on finish.
14. Complete the installation. This will now
launch the MySQL Workbench and the
MySQL Shell.
15. Once MySQL Workbench is installed, select the Local instance and enter the password.
Now, you can use the MySQL query tab to write your SQL queries.
MySQL Workbench
MySQL Workbench is a unified software used to add functionality and
ease to SQL development work. MySQL Workbench provides data
modeling, SQL development, and various administration tools for
configuration. It also offers a graphical interface to work with the
databases in a structured way.
With its comprehensive features, MySQL Workbench is a popularly used
software by businesses to manage their structured databases.
MySQL Workbench
MySQL Workbench provides data modeling, SQL development, and
various administration tools for configuration. It also offers a graphical
interface to work with the databases in a structured way.
- You can create a Graphical Model using MySQL Workbench
- MySQL Workbench provides reverse engineering for live databases to
models
- MySQL Workbench offers a forward engineering model to a scipt/live
database
MySQL
Workbench
The purpose of MySQL Workbench
is to provide the interface to work
with databases more easily and in a
more structured way.
MySQL workbench- Modeling
and Design Tool
• Models are at the core of most valid and high performance
databases. MySQL Workbench has tools that allow developers
and database administrators visually create physical database
design models that can be easily translated into MySQL
databases using forward engineering.
• MySQL workbench supports creation of multiple models in the
same environment.
• It supports all objects such as tables, views, stored procedures,
triggers, etc. that make up a database.
• MySQL workbench has a built in model validating utility that
reports any issues that might be found to the data modeler.
MySQL Workbench
Modeling window
MySQL workbench – SQL
EditorQuery Language (SQL) allows us to manipulate our relational
Structured
databases. SQL is at the heart of all relational databases
• MySQL workbench, has built in SQL visual editor.
• The Visual SQL editor allows developers to build, edit and run queries against
MySQL server databases. It has utilities for viewing data and exporting it.
• Its syntax color highlighters help developers easily write and debug SQL
statements.
• Multiple queries can be run and results automatically displayed in different tabs.
• The queries are also saved in the history panel for later retrieval and running.
MySQL Workbench SQL Development
Window
MySQL Workbench –
Administration tool
Server administration plays a critical role in securing the data of
the company. The major issues concerning server administration
are users’ management, server configuration, server logs and
many more.
MySQL Workbench –
Administration tool
MySQL Workbench has the following features that simplify the process of MySQL server
administration:
• User administration – visual utility for managing users that lets database administrators
easily add new and remove existing users if need arises, grant and drop privileges and view
user profiles.
• Server configuration – allows for advanced configuration of the server and fine tuning for
optimal performance.
• Database backup and restorations – visual tool for exporting/importing MySQL dump files.
MySQL dump files contain SQL scripts for creating databases, tables, views, stored
procedures and insertion of data.
• Server logs – visual tool for viewing MySQL server logs. The logs include error logs, binary
logs and InnodDB logs. These logs come in handy when performing diagnosis on the server.
MySQL Workbench – Admin
Panel
Commands
• You have just installed MySQL Server and MySQL Workbench.
• Now lets get started by learning some SQL commands
• Code is provided in notebooks for easy copy+paste