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

Configuring Oracle Enterprise Manager Cloud Control 12c for HA White Paper
Configuring Oracle Enterprise Manager Cloud Control 12c for HA White PaperConfiguring Oracle Enterprise Manager Cloud Control 12c for HA White Paper
Configuring Oracle Enterprise Manager Cloud Control 12c for HA White Paper
Leighton Nelson
 
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
Carlos Sierra
 

What's hot (20)

PLSQL Cursors
PLSQL CursorsPLSQL Cursors
PLSQL Cursors
 
Manipulating Data Oracle Data base
Manipulating Data Oracle Data baseManipulating Data Oracle Data base
Manipulating Data Oracle Data base
 
Oracle Forms : Query Triggers
Oracle Forms : Query TriggersOracle Forms : Query Triggers
Oracle Forms : Query Triggers
 
SQL
SQLSQL
SQL
 
How to find what is making your Oracle database slow
How to find what is making your Oracle database slowHow to find what is making your Oracle database slow
How to find what is making your Oracle database slow
 
Oracle Index
Oracle IndexOracle Index
Oracle Index
 
Unit 4 plsql
Unit 4  plsqlUnit 4  plsql
Unit 4 plsql
 
AWR & ASH Analysis
AWR & ASH AnalysisAWR & ASH Analysis
AWR & ASH Analysis
 
DOAG Oracle Unified Audit in Multitenant Environments
DOAG Oracle Unified Audit in Multitenant EnvironmentsDOAG Oracle Unified Audit in Multitenant Environments
DOAG Oracle Unified Audit in Multitenant Environments
 
Configuring Oracle Enterprise Manager Cloud Control 12c for HA White Paper
Configuring Oracle Enterprise Manager Cloud Control 12c for HA White PaperConfiguring Oracle Enterprise Manager Cloud Control 12c for HA White Paper
Configuring Oracle Enterprise Manager Cloud Control 12c for HA White Paper
 
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
 
Structured query language(sql)ppt
Structured query language(sql)pptStructured query language(sql)ppt
Structured query language(sql)ppt
 
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and AdvisorsYour tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
 
Producing Readable Output with iSQL*Plus - Oracle Data Base
Producing Readable Output with iSQL*Plus - Oracle Data BaseProducing Readable Output with iSQL*Plus - Oracle Data Base
Producing Readable Output with iSQL*Plus - Oracle Data Base
 
Em13c New Features- Two of Two
Em13c New Features- Two of TwoEm13c New Features- Two of Two
Em13c New Features- Two of Two
 
All About PL/SQL Collections
All About PL/SQL CollectionsAll About PL/SQL Collections
All About PL/SQL Collections
 
Difference between all topics in oracle
Difference between all topics in oracleDifference between all topics in oracle
Difference between all topics in oracle
 
Shell Scripts for Oracle Database and E-Business Suite.pdf
Shell Scripts for Oracle Database and E-Business Suite.pdfShell Scripts for Oracle Database and E-Business Suite.pdf
Shell Scripts for Oracle Database and E-Business Suite.pdf
 
Ldap
LdapLdap
Ldap
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
 

Viewers also liked

jquery cheat sheet
jquery cheat sheetjquery cheat sheet
jquery cheat sheet
johnnytomcat
 

Viewers also liked (14)

Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
Cheat sheet - String Java (Referência rápida)
Cheat sheet - String Java (Referência rápida)Cheat sheet - String Java (Referência rápida)
Cheat sheet - String Java (Referência rápida)
 
Cheat Sheet java
Cheat Sheet javaCheat Sheet java
Cheat Sheet java
 
jquery cheat sheet
jquery cheat sheetjquery cheat sheet
jquery 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
 
Java cheat sheet
Java cheat sheetJava cheat sheet
Java cheat sheet
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
Web Components Revolution
Web Components RevolutionWeb Components Revolution
Web Components Revolution
 
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
MySQL Cheat Sheet
MySQL Cheat SheetMySQL Cheat Sheet
MySQL Cheat Sheet
 
24 Books You've Never Heard Of - But Will Change Your Life
24 Books You've Never Heard Of - But Will Change Your Life24 Books You've Never Heard Of - But Will Change Your Life
24 Books You've Never Heard Of - But Will Change Your Life
 
20 Quotes To Turn Your Obstacles Into Opportunities
20 Quotes To Turn Your Obstacles Into Opportunities20 Quotes To Turn Your Obstacles Into Opportunities
20 Quotes To Turn Your Obstacles Into Opportunities
 
Work Rules!
Work Rules!Work Rules!
Work Rules!
 

Similar to MySQL Cheat Sheet

Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginners
ISsoft
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
Ashwin Dinoriya
 

Similar to MySQL Cheat Sheet (20)

SQL report
SQL reportSQL report
SQL report
 
MY SQL
MY SQLMY SQL
MY SQL
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginners
 
dbms.pdf
dbms.pdfdbms.pdf
dbms.pdf
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Sql slid
Sql slidSql slid
Sql slid
 
SQL
SQLSQL
SQL
 
Postgresql 9.3 overview
Postgresql 9.3 overviewPostgresql 9.3 overview
Postgresql 9.3 overview
 
Squirrel do more_with_less_code_cheat_sheet_1
Squirrel do more_with_less_code_cheat_sheet_1Squirrel do more_with_less_code_cheat_sheet_1
Squirrel do more_with_less_code_cheat_sheet_1
 
Squirrel do more_with_less_code_light_cheatsheet
Squirrel do more_with_less_code_light_cheatsheetSquirrel do more_with_less_code_light_cheatsheet
Squirrel do more_with_less_code_light_cheatsheet
 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML Commands
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
unit 1 ppt.pptx
unit 1 ppt.pptxunit 1 ppt.pptx
unit 1 ppt.pptx
 
1670595076250.pdf
1670595076250.pdf1670595076250.pdf
1670595076250.pdf
 
Cheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understandingCheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understanding
 
SQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdfSQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdf
 

More from Saeid Zebardast

More from Saeid Zebardast (9)

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
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 for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
هفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیمهفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیم
 
What is good design?
What is good design?What is good design?
What is good design?
 
How to be different?
How to be different?How to be different?
How to be different?
 
What is REST?
What is REST?What is REST?
What is REST?
 
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزادمعرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
 

Recently uploaded

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 

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: saeid.zebardast@gmail.com Home: http://zebardast.ir About: http://about.me/saeid Source: http://cheatography.com/guslong