SlideShare a Scribd company logo
MySQL Cheat Sheet 
MySQL Data Types 
CHAR String (0 - 255) 
VARCHAR String (0 - 255) 
TINYTEXT String (0 - 255) 
TEXT String (0 - 65535) 
BLOB String (0 - 65535) 
MEDIUMTEXT String (0 - 16777215) 
MEDIUMBLOB String (0 - 16777215) 
LONGTEXT String (0 - 4294967295) 
LONGBLOB String (0 - 4294967295) 
TINYINT x Integer (-128 to 127) 
SMALLINT x Integer (-32768 to 32767) 
MEDIUMINT x Integer (-8388608 to 8388607) 
INT x Integer (-2147483648 to 
2147483647) 
BIGINT x Integer 
(-9223372036854775808 to 
9223372036854775807) 
FLOAT Decimal (precise to 23 digits) 
DOUBLE Decimal (24 to 53 digits) 
DECIMAL "DOUBLE" stored as string 
DATE YYYY-MM-DD 
DATETIME YYYY-MM-DD HH:MM:SS 
TIMESTAMP YYYYMMDDHHMMSS 
TIME HH:MM:SS 
ENUM One of preset options 
SET Selection of preset options 
Integers (marked x) that are "UNSIGNED" have the 
same range of values but start from 0 (i.e., an 
UNSIGNED TINYINT can have any value from 0 to 
255). 
Select queries 
select all columns 
SELECT * FROM tbl; 
select some columns 
SELECT col1, col2 FROM tbl; 
select only unique records 
SELECT DISTINCT FROM tbl WHERE 
condition; 
column alias with AS 
SELECT col FROM tbl AS newname; 
order results 
SELECT * FROM tbl ORDER BY col [ASC | 
DESC]; 
group results 
SELECT col1, SUM(col2) FROM tbl GROUP BY 
col1; 
Creating and modifying 
create a database 
CREATE DATABASE db_name; 
select a database 
USE db_name; 
list the databases on the server 
SHOW DATABASES; 
show a table's fields 
DESCRIBE tbl; 
create a new table 
CREATE TABLE tbl (field1, field2); 
insert data into a table 
INSERT INTO tbl VALUES ("val1", "val2"); 
delete a row 
DELETE * FROM tbl WHERE condition; 
add a column from a table 
ALTER TABLE tbl ADD COLUMN col; 
remove a column from a table 
ALTER TABLE tbl DROP COLUMN col; 
make a column a primary key 
ALTER TABLE tbl ADD PRIMARY KEY (col); 
return only 1 row matching query 
... LIMIT = 1 
amend the values of a column 
UPDATE table SET column1="val1" WHERE ... 
clear all the values, leaving the table structure 
TRUNCATE TABLE tbl; 
delete the table 
DROP TABLE tbl; 
delete the database 
DROP DATABASE db_name; 
Matching data 
matching data using LIKE 
SELECT * FROM tbl1 WHERE col LIKE 
‘%value%’ 
matching data using REGEX 
SELECT * FROM tbl1 WHERE col RLIKE 
‘regular_expression’ 
Joins 
INNER 
JOIN 
returns only where match in both 
tables 
OUTER 
JOIN 
also returns non-matching records 
from both tables 
LEFT 
JOIN 
also returns non-matching records 
from left table 
RIGHT 
JOIN 
also returns non-matching records in 
right table 
JOIN syntax: 
SELECT * FROM tbl1 INNER JOIN tbl2 ON tbl1.id 
= tbl2.id; 
String functions MySQL 
Compare 
strings 
STRCMP("str1","str2") 
Convert to 
lower case 
LOWER("str") 
Convert to 
upper case 
UPPER("str") 
Left trim LTRIM("str") 
Substring of a 
string 
SUBSTRING("str","inx1","inx2") 
Concatenate CONCAT("str1","str2") 
MySQL calculation functions 
Count rows COUNT(col) 
Average AVG(col) 
Minimum value MIN(col) 
Maximum value MAX(col) 
Sum of values SUM(col) 
Create table with auto-incrementing primary key 
CREATE TABLE table_name ( 
id INT AUTO_INCREMENT, 
column VARCHAR(2), 
column VARCHAR(32), 
PRIMARY KEY (id) 
); 
Updated by Saeid Zebardast 
Twitter: @saeid 
Email: saeid.zebardast@gmail.com 
Home: http://zebardast.ir 
About: http://about.me/saeid 
Source: http://cheatography.com/guslong

More Related Content

What's hot (20)

PDF
Arrays in Java | Edureka
Edureka!
 
PPTX
EXPLORING VARIOUS UI INTERACTION PATTERNS
ROHISIVAM
 
ODP
Hyperledger Fabric and Tools
Rihusoft
 
PPTX
Flask – Python
Max Claus Nunes
 
PPT
Web browsers and website publishing
Gurleen Kaur
 
PPTX
Wikipedia
Laura Wilson
 
PPTX
Python Seminar PPT
Shivam Gupta
 
PDF
How to Create a YouTube Channel
Crackerjack Scribe
 
PPT
Amazon Web Services (AWS) Case study
المهندسة عائشة بني صخر
 
PPTX
Css font properties
Jesus Obenita Jr.
 
PPTX
Vectors in Java
Abhilash Nair
 
PPTX
Open Cloud Consortium Overview (01-10-10 V6)
Robert Grossman
 
PPTX
7. check box control
chauhankapil
 
PPTX
Basic html structure
Jhaun Paul Enriquez
 
PPTX
How to build a website
Bloxup
 
PPTX
Flask
Mamta Kumari
 
PPT
Web Development using HTML & CSS
Shashank Skills Academy
 
PPTX
Bootstrap PPT by Mukesh
Mukesh Kumar
 
PPTX
Sgml and xml
Jaya Kumari
 
Arrays in Java | Edureka
Edureka!
 
EXPLORING VARIOUS UI INTERACTION PATTERNS
ROHISIVAM
 
Hyperledger Fabric and Tools
Rihusoft
 
Flask – Python
Max Claus Nunes
 
Web browsers and website publishing
Gurleen Kaur
 
Wikipedia
Laura Wilson
 
Python Seminar PPT
Shivam Gupta
 
How to Create a YouTube Channel
Crackerjack Scribe
 
Amazon Web Services (AWS) Case study
المهندسة عائشة بني صخر
 
Css font properties
Jesus Obenita Jr.
 
Vectors in Java
Abhilash Nair
 
Open Cloud Consortium Overview (01-10-10 V6)
Robert Grossman
 
7. check box control
chauhankapil
 
Basic html structure
Jhaun Paul Enriquez
 
How to build a website
Bloxup
 
Web Development using HTML & CSS
Shashank Skills Academy
 
Bootstrap PPT by Mukesh
Mukesh Kumar
 
Sgml and xml
Jaya Kumari
 

Viewers also liked (14)

PDF
Java Cheat Sheet
Saeid Zebardast
 
PDF
Cheat sheet - String Java (Referência rápida)
Rafael Liberato
 
PDF
Cheat Sheet java
arkslideshareacc
 
PDF
jquery cheat sheet
johnnytomcat
 
PDF
Developing Applications with MySQL and Java for beginners
Saeid Zebardast
 
PDF
Java cheat sheet
Piyush Mittal
 
PDF
Java Cheat Sheet
GlowTouch
 
PDF
Web Components Revolution
Saeid Zebardast
 
PDF
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Noopur Gupta
 
PDF
Java for beginners
Saeid Zebardast
 
PDF
MySQL Cheat Sheet
Chen Dominique
 
PDF
24 Books You've Never Heard Of - But Will Change Your Life
Ryan Holiday
 
PDF
20 Quotes To Turn Your Obstacles Into Opportunities
Ryan Holiday
 
PDF
Work Rules!
Laszlo Bock
 
Java Cheat Sheet
Saeid Zebardast
 
Cheat sheet - String Java (Referência rápida)
Rafael Liberato
 
Cheat Sheet java
arkslideshareacc
 
jquery cheat sheet
johnnytomcat
 
Developing Applications with MySQL and Java for beginners
Saeid Zebardast
 
Java cheat sheet
Piyush Mittal
 
Java Cheat Sheet
GlowTouch
 
Web Components Revolution
Saeid Zebardast
 
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Noopur Gupta
 
Java for beginners
Saeid Zebardast
 
MySQL Cheat Sheet
Chen Dominique
 
24 Books You've Never Heard Of - But Will Change Your Life
Ryan Holiday
 
20 Quotes To Turn Your Obstacles Into Opportunities
Ryan Holiday
 
Work Rules!
Laszlo Bock
 
Ad

Similar to MySQL Cheat Sheet (20)

PDF
MySQL Cheat Sheet & Quick Referenece.pdf
vaibhavar253
 
PPTX
session_2 on database mysql databaseds from file to
zmulani8
 
PPTX
Session 2 - "MySQL Basics & Schema Design"
LogaRajeshwaranKarth
 
PPTX
2016 02 23_biological_databases_part2
Prof. Wim Van Criekinge
 
PDF
MySQL for beginners
Saeid Zebardast
 
PDF
DBMS 4 | MySQL - DDL & DML Commands
Mohammad Imam Hossain
 
PDF
Introducción rápida a SQL
Carlos Hernando
 
PPTX
2017 biological databasespart2
Prof. Wim Van Criekinge
 
PDF
Mysql basics1
Steffy Robert
 
PPTX
2018 02 20_biological_databases_part2_v_upload
Prof. Wim Van Criekinge
 
PPT
MySql slides (ppt)
webhostingguy
 
PPT
My SQL
Karan Kashyap
 
PPTX
Introduction To MySQL Lecture 1
Ajay Khatri
 
PPTX
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
sdnsdf
 
PPTX
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
teachersduniya.com
 
PPTX
MSAvMySQL.pptx
MattMarino13
 
PDF
Bt0075 rdbms with mysql 2
Techglyphs
 
PPT
Mangala Deshpande MySQL0710.ppt
Mihir Shah
 
PDF
•Design (create) 3 questions for a quiz show game and design regular.pdf
jyothimuppasani1
 
PPTX
Boosting MySQL (for starters)
Jose Luis Martínez
 
MySQL Cheat Sheet & Quick Referenece.pdf
vaibhavar253
 
session_2 on database mysql databaseds from file to
zmulani8
 
Session 2 - "MySQL Basics & Schema Design"
LogaRajeshwaranKarth
 
2016 02 23_biological_databases_part2
Prof. Wim Van Criekinge
 
MySQL for beginners
Saeid Zebardast
 
DBMS 4 | MySQL - DDL & DML Commands
Mohammad Imam Hossain
 
Introducción rápida a SQL
Carlos Hernando
 
2017 biological databasespart2
Prof. Wim Van Criekinge
 
Mysql basics1
Steffy Robert
 
2018 02 20_biological_databases_part2_v_upload
Prof. Wim Van Criekinge
 
MySql slides (ppt)
webhostingguy
 
Introduction To MySQL Lecture 1
Ajay Khatri
 
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
sdnsdf
 
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
teachersduniya.com
 
MSAvMySQL.pptx
MattMarino13
 
Bt0075 rdbms with mysql 2
Techglyphs
 
Mangala Deshpande MySQL0710.ppt
Mihir Shah
 
•Design (create) 3 questions for a quiz show game and design regular.pdf
jyothimuppasani1
 
Boosting MySQL (for starters)
Jose Luis Martínez
 
Ad

More from Saeid Zebardast (8)

PDF
Introduction to Redis
Saeid Zebardast
 
PDF
An Introduction to Apache Cassandra
Saeid Zebardast
 
PDF
An overview of Scalable Web Application Front-end
Saeid Zebardast
 
PDF
هفده اصل افراد موثر در تیم
Saeid Zebardast
 
PDF
What is good design?
Saeid Zebardast
 
PDF
How to be different?
Saeid Zebardast
 
PDF
What is REST?
Saeid Zebardast
 
PDF
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
Saeid Zebardast
 
Introduction to Redis
Saeid Zebardast
 
An Introduction to Apache Cassandra
Saeid Zebardast
 
An overview of Scalable Web Application Front-end
Saeid Zebardast
 
هفده اصل افراد موثر در تیم
Saeid Zebardast
 
What is good design?
Saeid Zebardast
 
How to be different?
Saeid Zebardast
 
What is REST?
Saeid Zebardast
 
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
Saeid Zebardast
 

Recently uploaded (20)

PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Biography of Daniel Podor.pdf
Daniel Podor
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 

MySQL Cheat Sheet

  • 1. MySQL Cheat Sheet MySQL Data Types CHAR String (0 - 255) VARCHAR String (0 - 255) TINYTEXT String (0 - 255) TEXT String (0 - 65535) BLOB String (0 - 65535) MEDIUMTEXT String (0 - 16777215) MEDIUMBLOB String (0 - 16777215) LONGTEXT String (0 - 4294967295) LONGBLOB String (0 - 4294967295) TINYINT x Integer (-128 to 127) SMALLINT x Integer (-32768 to 32767) MEDIUMINT x Integer (-8388608 to 8388607) INT x Integer (-2147483648 to 2147483647) BIGINT x Integer (-9223372036854775808 to 9223372036854775807) FLOAT Decimal (precise to 23 digits) DOUBLE Decimal (24 to 53 digits) DECIMAL "DOUBLE" stored as string DATE YYYY-MM-DD DATETIME YYYY-MM-DD HH:MM:SS TIMESTAMP YYYYMMDDHHMMSS TIME HH:MM:SS ENUM One of preset options SET Selection of preset options Integers (marked x) that are "UNSIGNED" have the same range of values but start from 0 (i.e., an UNSIGNED TINYINT can have any value from 0 to 255). Select queries select all columns SELECT * FROM tbl; select some columns SELECT col1, col2 FROM tbl; select only unique records SELECT DISTINCT FROM tbl WHERE condition; column alias with AS SELECT col FROM tbl AS newname; order results SELECT * FROM tbl ORDER BY col [ASC | DESC]; group results SELECT col1, SUM(col2) FROM tbl GROUP BY col1; Creating and modifying create a database CREATE DATABASE db_name; select a database USE db_name; list the databases on the server SHOW DATABASES; show a table's fields DESCRIBE tbl; create a new table CREATE TABLE tbl (field1, field2); insert data into a table INSERT INTO tbl VALUES ("val1", "val2"); delete a row DELETE * FROM tbl WHERE condition; add a column from a table ALTER TABLE tbl ADD COLUMN col; remove a column from a table ALTER TABLE tbl DROP COLUMN col; make a column a primary key ALTER TABLE tbl ADD PRIMARY KEY (col); return only 1 row matching query ... LIMIT = 1 amend the values of a column UPDATE table SET column1="val1" WHERE ... clear all the values, leaving the table structure TRUNCATE TABLE tbl; delete the table DROP TABLE tbl; delete the database DROP DATABASE db_name; Matching data matching data using LIKE SELECT * FROM tbl1 WHERE col LIKE ‘%value%’ matching data using REGEX SELECT * FROM tbl1 WHERE col RLIKE ‘regular_expression’ Joins INNER JOIN returns only where match in both tables OUTER JOIN also returns non-matching records from both tables LEFT JOIN also returns non-matching records from left table RIGHT JOIN also returns non-matching records in right table JOIN syntax: SELECT * FROM tbl1 INNER JOIN tbl2 ON tbl1.id = tbl2.id; String functions MySQL Compare strings STRCMP("str1","str2") Convert to lower case LOWER("str") Convert to upper case UPPER("str") Left trim LTRIM("str") Substring of a string SUBSTRING("str","inx1","inx2") Concatenate CONCAT("str1","str2") MySQL calculation functions Count rows COUNT(col) Average AVG(col) Minimum value MIN(col) Maximum value MAX(col) Sum of values SUM(col) Create table with auto-incrementing primary key CREATE TABLE table_name ( id INT AUTO_INCREMENT, column VARCHAR(2), column VARCHAR(32), PRIMARY KEY (id) ); Updated by Saeid Zebardast Twitter: @saeid Email: [email protected] Home: http://zebardast.ir About: http://about.me/saeid Source: http://cheatography.com/guslong