SlideShare a Scribd company logo
Saeid Zebardast 
@saeid 
http://about.me/saeid 
saeid.zebardast@gmail.com 
1
Please Please Please 
Ask Questions 
As Much As You Like 
• This is not a lecture! 
- But an opportunity to learn 
from each other. 
- If you haven’t seen some of 
these frameworks, methods, 
etc. It is OK! 
- Let we know if you know 
‣ Better ways 
‣ Best practices 
‣ My mistakes!
Introduction 
• What’s MySQL? 
- Since 1995 
- Written in C/C++ 
- RDMBS (Relational Database Management 
System) 
3
Installation 
• Just enter the following command: 
- $ sudo apt-get install mysql-server mysql-client 
• Check MySQL CLI: 
- $ mysql -u root -p 
- mysql> SHOW DATABASES; 
4
Execute SQL Statements 
• Interactively 
- $ mysql [database] 
‣ mysql> stmt; 
• Command Line 
- $ mysql [database] -e ‘stmt’ 
• A file or a pipe 
- $ mysql [database] < stmt_file 
- $ cat stmt_file | mysql [database] 
5
SQL Language 
• SQL (Structured Query Language) 
- Provided by RDBMS 
- Data Definition (DDL) 
‣ CREATE TABLE, DROP DATABASE 
- Data Manipulation (DDL) 
‣ SELECT, INSERT, UPDATE, DELETE 
- Data Control (DCL) 
‣ GRANT, REVOKE 
6
Some of The Most Important 
SQL Commands 
• SELECT - extracts data from a database 
• UPDATE - updates data in a database 
• DELETE - deletes data from a database 
• INSERT INTO - inserts new data into a database 
• CREATE DATABASE - creates a new database 
• ALTER DATABASE - modifies a database 
• USE DATABASE - choose a database to execute a statement 
• CREATE TABLE - creates a new table 
• ALTER TABLE - modifies a table 
• DROP TABLE - deletes a table 
• CREATE INDEX - creates an index (search key) 
• DROP INDEX - deletes an index 
7
SQL Syntax 
• SQL is NOT case sensitive: select is the same as 
SELECT 
• Semicolon (;) after SQL Statements 
- or G 
8
Data Types 
Integer 
Type Min Max 2^ 
TINYINT -128 127 2^7 
SMALLINT -32,768 32,767 2^15 
MEDIUMINT -8,388,608 8,388,607 2^23 
INT -2,147,483,648 2,147,483,647 2^31 
BIGINT -9,223,372,036,854,775,808 9,223,372,036,854,775,807 2^63 
Note: If unsigned, the allowable range is from 0 to twice the Max.
Data Types 
Floating-point 
Type Description 
FLOAT(M,D) 
A small number with a floating decimal point. 
Size or Display length (M), Decimals (D) 
0, 23 
DOUBLE(M,D) 
A large number with a floating decimal point. 
0, 53 
DECIMAL(M,D) 0, 65
Data Types 
Date and Time 
Type Description 
DATE 
YYYY-MM-DD format. 
between 1000-01-01 and 9999-12-31. 
DATETIME 
YYYY-MM-DD HH:MM:SS format. 
between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. 
TIMESTAMP 
stored as the number of seconds since the Unix epoch 1970-01-01 
between 1970-01-01 00:00:01 and 2038-01-09 03:14:07. 
TIME HH:MM:SS 
YEAR 1901 to 2155
Data Types 
String 
Type Description 
CHAR 
A fixed-length string between 1 and 255 characters. 
right-padded with spaces. 
VARCHAR A variable-length string between 1 and 255 characters. 
0 to 65,535 in 5.0.3 
TINYTEXT 
TINYBLOB up to 255 characters 
TEXT 
BLOB up to 65,535 characters 
MEDIUMTEXT 
MEDIUMBLOB up to 16,777,215 characters 
LONGTEXT 
LONGBLOB up to 4,294,967,295 characters 
ENUM List of items. For example: ENUM ('A', 'B', 'C') 
Note: case sensitive on BLOBs and are not case sensitive in TEXT fields.
Operators 
(Most Used) 
Operator Description 
= (A = B) is not true. 
!= 
(A != B) is true. 
<> 
> (A > B) is not true. 
< (A < B) is true. 
>= (A >= B) is not true. 
<= (A <= B) is true. 
LIKE Simple pattern matching 
BETWEEN ... AND ... Check whether a value is within a range of values
Basic Syntax 
• Create Database 
- CREATE DATABASE db_name 
• Create Table 
- CREATE TABLE table_name (column_name column_type, …); 
• Insert Data 
- INSERT INTO table_name (field1, field2,...fieldN) VALUES (value1, value2, …valueN); 
• Select Data 
- SELECT field1, field2,...fieldN table_name1, table_name2... [WHERE condition1 [AND -OR condition2]….] 
• Update Data 
- UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause] 
• Delete Data 
- DELETE FROM table_name [WHERE Clause] 
• Sorting Result 
- SELECT field1, field2,...fieldN table_name1, table_name2… ORDER BY field1, [field2...] [ASC [DESC]] 
14
15
Exercise 1 
Data Definition, Data Control 
• Create database `workshop` 
- mysql> CREATE DATABASE `workshop`; 
mysql> USE `workshop`; 
• Grant all privileges to the database user `worker` 
- mysql> GRANT ALL PRIVILEGES on `workshop`.* to `worker`@localhost identified by ‘123456'; 
- mysql> exit; 
• Create table `workshops_list` 
- mysql> CREATE TABLE `workshops_list` ( 
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, 
`title` VARCHAR(255) NOT NULL, 
`description` MEDIUMTEXT DEFAULT NULL, 
PRIMARY KEY(`id`) 
); 
- DESC `workshops_list`; 
16
Exercise 2 
Data Manipulation 
• Show data 
- mysql> SELECT * FROM `workshops_list`; 
• Insert data 
- mysql> INSERT INTO `workshops_list`(`title`) VALUES ('MySQL Workshop'), ('Java Workshop'), 
('Ubuntu'), ('Windows 10’); 
- mysql> SELECT * FROM `workshops_list` G 
• Update data 
- mysql> UPDATE `workshops_list` SET `description` = 'Introduce MySQL database' WHERE id = 1; 
- … 
- mysql> SELECT * FROM `workshops_list` ORDER BY `id` DESC; 
• Remove data 
- mysql> DELETE FROM `workshops_list` WHERE title = 'Windows 10’; 
- mysql> SELECT * FROM `workshops_list` ORDER BY `title` ASC; 
17
Exercise 3 
Export and Import 
• Export database dump. you might want to take a look at the 
contents. 
- $ mysqldump -u worker -p workshop > workshop.sql 
- $ less workshop.sql 
• Delete database `workshop` 
- mysql> DROP DATABASE `workshop`; 
• Import database dump file. 
- $ mysql -u worker -p < workshop.sql 
18
Read The F* Manual 
• RTFM 
- https://dev.mysql.com/doc/ 
• Help 
- mysql> HELP; 
- mysql> HELP CONTENTS; 
- mysql> HELP SELECT; 
19
Thank You
Ad

More Related Content

What's hot (20)

DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
Sankhya_Analytics
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
Shakila Mahjabin
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
webhostingguy
 
MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
mysql content
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
SQL Data types and Constarints.pptx
SQL Data types and Constarints.pptxSQL Data types and Constarints.pptx
SQL Data types and Constarints.pptx
jaba kumar
 
MySQL
MySQLMySQL
MySQL
Gouthaman V
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
ammarbrohi
 
SQL
SQLSQL
SQL
Shunya Ram
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
SQL Views
SQL ViewsSQL Views
SQL Views
Aaron Buma
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
bixxman
 
Stored procedure
Stored procedureStored procedure
Stored procedure
baabtra.com - No. 1 supplier of quality freshers
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
Dhani Ahmad
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
SQL Views
SQL ViewsSQL Views
SQL Views
baabtra.com - No. 1 supplier of quality freshers
 
AGGREGATE FUNCTION.pptx
AGGREGATE FUNCTION.pptxAGGREGATE FUNCTION.pptx
AGGREGATE FUNCTION.pptx
Anusha sivakumar
 

Viewers also liked (17)

MySQL for Beginners - part 1
MySQL for Beginners - part 1MySQL for Beginners - part 1
MySQL for Beginners - part 1
Ivan Zoratti
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
Giuseppe Maxia
 
MySQL Guide for Beginners
MySQL Guide for BeginnersMySQL Guide for Beginners
MySQL Guide for Beginners
Dainis Graveris
 
Installing MySQL for Python
Installing MySQL for PythonInstalling MySQL for Python
Installing MySQL for Python
Siva Arunachalam
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
What is good design?
What is good design?What is good design?
What is good design?
Saeid Zebardast
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Saeid Zebardast
 
What is REST?
What is REST?What is REST?
What is REST?
Saeid Zebardast
 
How to be different?
How to be different?How to be different?
How to be different?
Saeid Zebardast
 
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریفمعرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
numb95
 
مستندات رفتاری در انجمنهای نرم افزار های آزاد
مستندات رفتاری در انجمنهای نرم افزار های آزادمستندات رفتاری در انجمنهای نرم افزار های آزاد
مستندات رفتاری در انجمنهای نرم افزار های آزاد
numb95
 
Web Components Revolution
Web Components RevolutionWeb Components Revolution
Web Components Revolution
Saeid Zebardast
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
Saeid Zebardast
 
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB ClusterMySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
Olivier DASINI
 
Mysql introduction
Mysql introduction Mysql introduction
Mysql introduction
Prof. Wim Van Criekinge
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
Guru Ji
 
MySQL for Beginners - part 1
MySQL for Beginners - part 1MySQL for Beginners - part 1
MySQL for Beginners - part 1
Ivan Zoratti
 
MySQL Guide for Beginners
MySQL Guide for BeginnersMySQL Guide for Beginners
MySQL Guide for Beginners
Dainis Graveris
 
Installing MySQL for Python
Installing MySQL for PythonInstalling MySQL for Python
Installing MySQL for Python
Siva Arunachalam
 
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریفمعرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
numb95
 
مستندات رفتاری در انجمنهای نرم افزار های آزاد
مستندات رفتاری در انجمنهای نرم افزار های آزادمستندات رفتاری در انجمنهای نرم افزار های آزاد
مستندات رفتاری در انجمنهای نرم افزار های آزاد
numb95
 
Web Components Revolution
Web Components RevolutionWeb Components Revolution
Web Components Revolution
Saeid Zebardast
 
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB ClusterMySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
Olivier DASINI
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
Guru Ji
 
Ad

Similar to MySQL for beginners (20)

xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
NilamHonmane
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
Mudasir Syed
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQL
Naeem Junejo
 
Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
Subhasis Nayak
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
Subhasis Nayak
 
Mysql-overview.pptx
Mysql-overview.pptxMysql-overview.pptx
Mysql-overview.pptx
TamilHunt
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
TamiratDejene1
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
StephenEfange3
 
Training on Microsoft SQL Server(older version).pptx
Training on Microsoft SQL Server(older version).pptxTraining on Microsoft SQL Server(older version).pptx
Training on Microsoft SQL Server(older version).pptx
naibedyakar00
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
smumbahelp
 
SQL on Linux and its uses and application.pdf
SQL on Linux and its uses and application.pdfSQL on Linux and its uses and application.pdf
SQL on Linux and its uses and application.pdf
bhaveshsethi456
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
smumbahelp
 
Data Base Management 1 Database Management.pptx
Data Base Management 1 Database Management.pptxData Base Management 1 Database Management.pptx
Data Base Management 1 Database Management.pptx
PreeTVithule1
 
My sql1
My sql1My sql1
My sql1
Akash Gupta
 
Oracle notes
Oracle notesOracle notes
Oracle notes
Prashant Dadmode
 
Module02
Module02Module02
Module02
Sridhar P
 
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdfComplete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
ssuserb5bb0e
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
YashaswiniSrinivasan1
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
Mudasir Syed
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQL
Naeem Junejo
 
Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
Subhasis Nayak
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
Subhasis Nayak
 
Mysql-overview.pptx
Mysql-overview.pptxMysql-overview.pptx
Mysql-overview.pptx
TamilHunt
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
TamiratDejene1
 
Training on Microsoft SQL Server(older version).pptx
Training on Microsoft SQL Server(older version).pptxTraining on Microsoft SQL Server(older version).pptx
Training on Microsoft SQL Server(older version).pptx
naibedyakar00
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
smumbahelp
 
SQL on Linux and its uses and application.pdf
SQL on Linux and its uses and application.pdfSQL on Linux and its uses and application.pdf
SQL on Linux and its uses and application.pdf
bhaveshsethi456
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
smumbahelp
 
Data Base Management 1 Database Management.pptx
Data Base Management 1 Database Management.pptxData Base Management 1 Database Management.pptx
Data Base Management 1 Database Management.pptx
PreeTVithule1
 
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdfComplete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
ssuserb5bb0e
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
YashaswiniSrinivasan1
 
Ad

More from Saeid Zebardast (7)

An Introduction to Apache Cassandra
An Introduction to Apache CassandraAn Introduction to Apache Cassandra
An Introduction to Apache Cassandra
Saeid Zebardast
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-end
Saeid Zebardast
 
MySQL Cheat Sheet
MySQL Cheat SheetMySQL Cheat Sheet
MySQL Cheat Sheet
Saeid Zebardast
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
Saeid Zebardast
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
Saeid Zebardast
 
هفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیمهفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیم
Saeid Zebardast
 
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزادمعرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
Saeid Zebardast
 
An Introduction to Apache Cassandra
An Introduction to Apache CassandraAn Introduction to Apache Cassandra
An Introduction to Apache Cassandra
Saeid Zebardast
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-end
Saeid Zebardast
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
Saeid Zebardast
 
هفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیمهفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیم
Saeid Zebardast
 
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزادمعرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
Saeid Zebardast
 

Recently uploaded (20)

tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 

MySQL for beginners

  • 1. Saeid Zebardast @saeid http://about.me/saeid [email protected] 1
  • 2. Please Please Please Ask Questions As Much As You Like • This is not a lecture! - But an opportunity to learn from each other. - If you haven’t seen some of these frameworks, methods, etc. It is OK! - Let we know if you know ‣ Better ways ‣ Best practices ‣ My mistakes!
  • 3. Introduction • What’s MySQL? - Since 1995 - Written in C/C++ - RDMBS (Relational Database Management System) 3
  • 4. Installation • Just enter the following command: - $ sudo apt-get install mysql-server mysql-client • Check MySQL CLI: - $ mysql -u root -p - mysql> SHOW DATABASES; 4
  • 5. Execute SQL Statements • Interactively - $ mysql [database] ‣ mysql> stmt; • Command Line - $ mysql [database] -e ‘stmt’ • A file or a pipe - $ mysql [database] < stmt_file - $ cat stmt_file | mysql [database] 5
  • 6. SQL Language • SQL (Structured Query Language) - Provided by RDBMS - Data Definition (DDL) ‣ CREATE TABLE, DROP DATABASE - Data Manipulation (DDL) ‣ SELECT, INSERT, UPDATE, DELETE - Data Control (DCL) ‣ GRANT, REVOKE 6
  • 7. Some of The Most Important SQL Commands • SELECT - extracts data from a database • UPDATE - updates data in a database • DELETE - deletes data from a database • INSERT INTO - inserts new data into a database • CREATE DATABASE - creates a new database • ALTER DATABASE - modifies a database • USE DATABASE - choose a database to execute a statement • CREATE TABLE - creates a new table • ALTER TABLE - modifies a table • DROP TABLE - deletes a table • CREATE INDEX - creates an index (search key) • DROP INDEX - deletes an index 7
  • 8. SQL Syntax • SQL is NOT case sensitive: select is the same as SELECT • Semicolon (;) after SQL Statements - or G 8
  • 9. Data Types Integer Type Min Max 2^ TINYINT -128 127 2^7 SMALLINT -32,768 32,767 2^15 MEDIUMINT -8,388,608 8,388,607 2^23 INT -2,147,483,648 2,147,483,647 2^31 BIGINT -9,223,372,036,854,775,808 9,223,372,036,854,775,807 2^63 Note: If unsigned, the allowable range is from 0 to twice the Max.
  • 10. Data Types Floating-point Type Description FLOAT(M,D) A small number with a floating decimal point. Size or Display length (M), Decimals (D) 0, 23 DOUBLE(M,D) A large number with a floating decimal point. 0, 53 DECIMAL(M,D) 0, 65
  • 11. Data Types Date and Time Type Description DATE YYYY-MM-DD format. between 1000-01-01 and 9999-12-31. DATETIME YYYY-MM-DD HH:MM:SS format. between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. TIMESTAMP stored as the number of seconds since the Unix epoch 1970-01-01 between 1970-01-01 00:00:01 and 2038-01-09 03:14:07. TIME HH:MM:SS YEAR 1901 to 2155
  • 12. Data Types String Type Description CHAR A fixed-length string between 1 and 255 characters. right-padded with spaces. VARCHAR A variable-length string between 1 and 255 characters. 0 to 65,535 in 5.0.3 TINYTEXT TINYBLOB up to 255 characters TEXT BLOB up to 65,535 characters MEDIUMTEXT MEDIUMBLOB up to 16,777,215 characters LONGTEXT LONGBLOB up to 4,294,967,295 characters ENUM List of items. For example: ENUM ('A', 'B', 'C') Note: case sensitive on BLOBs and are not case sensitive in TEXT fields.
  • 13. Operators (Most Used) Operator Description = (A = B) is not true. != (A != B) is true. <> > (A > B) is not true. < (A < B) is true. >= (A >= B) is not true. <= (A <= B) is true. LIKE Simple pattern matching BETWEEN ... AND ... Check whether a value is within a range of values
  • 14. Basic Syntax • Create Database - CREATE DATABASE db_name • Create Table - CREATE TABLE table_name (column_name column_type, …); • Insert Data - INSERT INTO table_name (field1, field2,...fieldN) VALUES (value1, value2, …valueN); • Select Data - SELECT field1, field2,...fieldN table_name1, table_name2... [WHERE condition1 [AND -OR condition2]….] • Update Data - UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause] • Delete Data - DELETE FROM table_name [WHERE Clause] • Sorting Result - SELECT field1, field2,...fieldN table_name1, table_name2… ORDER BY field1, [field2...] [ASC [DESC]] 14
  • 15. 15
  • 16. Exercise 1 Data Definition, Data Control • Create database `workshop` - mysql> CREATE DATABASE `workshop`; mysql> USE `workshop`; • Grant all privileges to the database user `worker` - mysql> GRANT ALL PRIVILEGES on `workshop`.* to `worker`@localhost identified by ‘123456'; - mysql> exit; • Create table `workshops_list` - mysql> CREATE TABLE `workshops_list` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL, `description` MEDIUMTEXT DEFAULT NULL, PRIMARY KEY(`id`) ); - DESC `workshops_list`; 16
  • 17. Exercise 2 Data Manipulation • Show data - mysql> SELECT * FROM `workshops_list`; • Insert data - mysql> INSERT INTO `workshops_list`(`title`) VALUES ('MySQL Workshop'), ('Java Workshop'), ('Ubuntu'), ('Windows 10’); - mysql> SELECT * FROM `workshops_list` G • Update data - mysql> UPDATE `workshops_list` SET `description` = 'Introduce MySQL database' WHERE id = 1; - … - mysql> SELECT * FROM `workshops_list` ORDER BY `id` DESC; • Remove data - mysql> DELETE FROM `workshops_list` WHERE title = 'Windows 10’; - mysql> SELECT * FROM `workshops_list` ORDER BY `title` ASC; 17
  • 18. Exercise 3 Export and Import • Export database dump. you might want to take a look at the contents. - $ mysqldump -u worker -p workshop > workshop.sql - $ less workshop.sql • Delete database `workshop` - mysql> DROP DATABASE `workshop`; • Import database dump file. - $ mysql -u worker -p < workshop.sql 18
  • 19. Read The F* Manual • RTFM - https://dev.mysql.com/doc/ • Help - mysql> HELP; - mysql> HELP CONTENTS; - mysql> HELP SELECT; 19