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

PDF
Classes and objects in java
PPSX
OOP with Java - Continued
PPTX
Software development best practices & coding guidelines
PDF
PDF
Exercice 2 java Héritage
PPTX
Java abstract class & abstract methods
PPT
Abstract class in java
PPTX
Interface in java
Classes and objects in java
OOP with Java - Continued
Software development best practices & coding guidelines
Exercice 2 java Héritage
Java abstract class & abstract methods
Abstract class in java
Interface in java

What's hot (20)

PPSX
Exception Handling
PPSX
Collections - Maps
PPTX
New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx
PPTX
Interfaces in java
PPTX
Advance oops concepts
PPT
PPT
PPTX
Flutter and ML Kit For Firebase
PPT
Runnable interface.34
PPTX
Java 101
PPT
Inheritance C#
PPTX
Namespace in C++ Programming Language
PDF
Strings in java
PPTX
Diagrammes de classes uml
PPTX
Ruby programming
PPT
Java Collections Framework
PPT
Serialization/deserialization
PDF
Introduction à ASP.NET
DOCX
Java collections notes
Exception Handling
Collections - Maps
New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx
Interfaces in java
Advance oops concepts
Flutter and ML Kit For Firebase
Runnable interface.34
Java 101
Inheritance C#
Namespace in C++ Programming Language
Strings in java
Diagrammes de classes uml
Ruby programming
Java Collections Framework
Serialization/deserialization
Introduction à ASP.NET
Java collections notes
Ad

Viewers also liked (14)

PDF
Java Cheat Sheet
PDF
Cheat sheet - String Java (Referência rápida)
PDF
Cheat Sheet java
PDF
jquery cheat sheet
PDF
Developing Applications with MySQL and Java for beginners
PDF
Java cheat sheet
PDF
Java Cheat Sheet
PDF
Web Components Revolution
PDF
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
PDF
Java for beginners
PDF
MySQL Cheat Sheet
PDF
24 Books You've Never Heard Of - But Will Change Your Life
PDF
20 Quotes To Turn Your Obstacles Into Opportunities
PDF
Work Rules!
Java Cheat Sheet
Cheat sheet - String Java (Referência rápida)
Cheat Sheet java
jquery cheat sheet
Developing Applications with MySQL and Java for beginners
Java cheat sheet
Java Cheat Sheet
Web Components Revolution
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Java for beginners
MySQL Cheat Sheet
24 Books You've Never Heard Of - But Will Change Your Life
20 Quotes To Turn Your Obstacles Into Opportunities
Work Rules!
Ad

Similar to MySQL Cheat Sheet (20)

DOCX
SQL report
PPT
MY SQL
PPT
Mysql 120831075600-phpapp01
PPTX
Sql practise for beginners
PDF
dbms.pdf
PPTX
DDL,DML,SQL Functions and Joins
ODP
PPT
PPTX
advanced mySQL Database tutorials and RDBMS tutorials.pptx
PPTX
Sql slid
PPTX
PDF
Postgresql 9.3 overview
PDF
Squirrel do more_with_less_code_cheat_sheet_1
PDF
Squirrel do more_with_less_code_light_cheatsheet
PDF
WORKSHEET SQL SOLVED FOR CLASS XII FINAL
PDF
DBMS 4 | MySQL - DDL & DML Commands
PDF
python_avw - Unit-03.pdf
PPTX
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
PPTX
unit 1 ppt.pptx
SQL report
MY SQL
Mysql 120831075600-phpapp01
Sql practise for beginners
dbms.pdf
DDL,DML,SQL Functions and Joins
advanced mySQL Database tutorials and RDBMS tutorials.pptx
Sql slid
Postgresql 9.3 overview
Squirrel do more_with_less_code_cheat_sheet_1
Squirrel do more_with_less_code_light_cheatsheet
WORKSHEET SQL SOLVED FOR CLASS XII FINAL
DBMS 4 | MySQL - DDL & DML Commands
python_avw - Unit-03.pdf
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
unit 1 ppt.pptx

More from Saeid Zebardast (9)

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

Recently uploaded (20)

PPTX
How Much Does It Cost to Build a Train Ticket App like Trenitalia in Italy.pptx
PDF
SparkLabs Primer on Artificial Intelligence 2025
PDF
REPORT: Heating appliances market in Poland 2024
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
PDF
Dell Pro 14 Plus: Be better prepared for what’s coming
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Why Endpoint Security Is Critical in a Remote Work Era?
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Software Development Methodologies in 2025
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
How Much Does It Cost to Build a Train Ticket App like Trenitalia in Italy.pptx
SparkLabs Primer on Artificial Intelligence 2025
REPORT: Heating appliances market in Poland 2024
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
Dell Pro 14 Plus: Be better prepared for what’s coming
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
Revolutionize Operations with Intelligent IoT Monitoring and Control
Understanding_Digital_Forensics_Presentation.pptx
Why Endpoint Security Is Critical in a Remote Work Era?
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
NewMind AI Weekly Chronicles - July'25 - Week IV
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Software Development Methodologies in 2025
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
NewMind AI Monthly Chronicles - July 2025
Enable Enterprise-Ready Security on IBM i Systems.pdf
A Day in the Life of Location Data - Turning Where into How.pdf

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