SlideShare a Scribd company logo
1 of 20
Download to read offline
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

More Related Content

What's hot

Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)Sabana Maharjan
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentationNITISH KUMAR
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Punjab University
 
SQL Queries
SQL QueriesSQL Queries
SQL QueriesNilt1234
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries InformationNishant Munjal
 
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
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaEdureka!
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schoolsfarhan516
 
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...Edureka!
 

What's hot (20)

Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
MySQL
MySQLMySQL
MySQL
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Introduction to Mysql
Introduction to MysqlIntroduction to Mysql
Introduction to Mysql
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
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...
 
PostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | EdurekaPostgreSQL Tutorial For Beginners | Edureka
PostgreSQL Tutorial For Beginners | Edureka
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schools
 
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
MySQL Workbench Tutorial | Introduction To MySQL Workbench | MySQL DBA Traini...
 

Viewers also liked

MySQL for Beginners - part 1
MySQL for Beginners - part 1MySQL for Beginners - part 1
MySQL for Beginners - part 1Ivan Zoratti
 
MySQL Guide for Beginners
MySQL Guide for BeginnersMySQL Guide for Beginners
MySQL Guide for BeginnersDainis Graveris
 
Installing MySQL for Python
Installing MySQL for PythonInstalling MySQL for Python
Installing MySQL for PythonSiva Arunachalam
 
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریفمعرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریفnumb95
 
مستندات رفتاری در انجمنهای نرم افزار های آزاد
مستندات رفتاری در انجمنهای نرم افزار های آزادمستندات رفتاری در انجمنهای نرم افزار های آزاد
مستندات رفتاری در انجمنهای نرم افزار های آزادnumb95
 
Web Components Revolution
Web Components RevolutionWeb Components Revolution
Web Components RevolutionSaeid 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 ClusterOlivier DASINI
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For BeginnersPriti 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 PresentationGuru Ji
 

Viewers also liked (17)

MySQL for Beginners - part 1
MySQL for Beginners - part 1MySQL for Beginners - part 1
MySQL for Beginners - part 1
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
MySQL Guide for Beginners
MySQL Guide for BeginnersMySQL Guide for Beginners
MySQL Guide for Beginners
 
Installing MySQL for Python
Installing MySQL for PythonInstalling MySQL for Python
Installing MySQL for Python
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
What is good design?
What is good design?What is good design?
What is good design?
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
What is REST?
What is REST?What is REST?
What is REST?
 
How to be different?
How to be different?How to be different?
How to be different?
 
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریفمعرفی سیستم‌های توکار در دانشگاه صنعتی شریف
معرفی سیستم‌های توکار در دانشگاه صنعتی شریف
 
مستندات رفتاری در انجمنهای نرم افزار های آزاد
مستندات رفتاری در انجمنهای نرم افزار های آزادمستندات رفتاری در انجمنهای نرم افزار های آزاد
مستندات رفتاری در انجمنهای نرم افزار های آزاد
 
Web Components Revolution
Web Components RevolutionWeb Components Revolution
Web Components Revolution
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
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
 
Mysql introduction
Mysql introduction Mysql introduction
Mysql introduction
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
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
 

Similar to MySQL for beginners

xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytWrushabhShirsat3
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQLNaeem Junejo
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir Syed
 
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.pptxTamilHunt
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfTamiratDejene1
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sqlsmumbahelp
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sqlsmumbahelp
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL ISankhya_Analytics
 
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.pdfssuserb5bb0e
 
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.pptxYashaswiniSrinivasan1
 
My sql with querys
My sql with querysMy sql with querys
My sql with querysNIRMAL FELIX
 

Similar to MySQL for beginners (20)

unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQL
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
 
Mysql-overview.pptx
Mysql-overview.pptxMysql-overview.pptx
Mysql-overview.pptx
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
My sql1
My sql1My sql1
My sql1
 
Oracle notes
Oracle notesOracle notes
Oracle notes
 
Module02
Module02Module02
Module02
 
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
 
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
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 

More from Saeid Zebardast

An Introduction to Apache Cassandra
An Introduction to Apache CassandraAn Introduction to Apache Cassandra
An Introduction to Apache CassandraSaeid 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-endSaeid 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 beginnersSaeid Zebardast
 
هفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیمهفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیمSaeid Zebardast
 
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزادمعرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزادSaeid Zebardast
 

More from Saeid Zebardast (7)

An Introduction to Apache Cassandra
An Introduction to Apache CassandraAn Introduction to Apache Cassandra
An Introduction to Apache Cassandra
 
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
 
MySQL Cheat Sheet
MySQL Cheat SheetMySQL Cheat Sheet
MySQL Cheat Sheet
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
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
 
هفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیمهفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیم
 
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزادمعرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

MySQL for beginners

  • 1. Saeid Zebardast @saeid http://about.me/saeid saeid.zebardast@gmail.com 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