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
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQLNicole Ryan
 
SQL Queries
SQL QueriesSQL Queries
SQL QueriesNilt1234
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
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 - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introductionSmriti Jain
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQLPooja Dixit
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?CPD INDIA
 

What's hot (20)

Mysql
MysqlMysql
Mysql
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
MYSQL
MYSQLMYSQL
MYSQL
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
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)
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
Mysql database
Mysql databaseMysql database
Mysql database
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
 
Sql commands
Sql commandsSql commands
Sql commands
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
MySQL ppt
MySQL ppt MySQL ppt
MySQL ppt
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 

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
 
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
 
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Ravikumar Nandigam
 

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
 
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
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
 
Sql
SqlSql
Sql
 

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

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
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
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
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
 

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