Show Menu
Cheatography

MySQL 5.7 Cheat Sheet (DRAFT) by

Common MySQL commands

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Basic Commands

List available databases
SHOW DATABASES;
Create a new database
CREATE DATABASE 'db name';
Select a database
USE 'db name';
Show tables in current database
SHOW TABLES;
Show table structure
DESCRIBE table;
Create a new user
CREATE USER 'user'­@'l­oca­lhost' IDENTIFIED BY 'passw­ord';
Drop a user
DROP USER 'user'­@'l­oca­lhost';
Grant privileges to a user
GRANT ALL PRIVILEGES ON *.* TO 'user'­@'l­oca­lhost';
Quit and logout of MySQL
quit
Grant Permis­sions are one of: ALL PRIVIL­EGES, CREATE, DROP, DELETE, INSERT, SELECT, UPDATE or GRANT OPTION
   

Selecting Data

Return everything
SELECT * FROM 'table';
Return some columns
SELECT column­1,c­olumn2 FROM 'table';
Return unique records
SLEECT DISTINCT FROM 'table' WHERE 'condition to meet'
Sort results
SELECT * FROM 'table' ORDER BY column1 [ASC|D­ESC];
Group results
SELECT column­1,c­olu­mn2­,CO­UNT­(co­lumn3) FROM 'table' GROUP BY column1;