mysql – Cheat Sheet



# Connect
mysql -u <username> -p
mysql -u <username> -p <database>


SHOW DATABASES;             # lists all available databasess
CREATE DATABASE <database>  # create a database
USE <database>              # select databasew databasess;


SHOW TABLES                 # lists all available tables
DESCRIBE <table>            # show table structure
SHOW INDEX FROM <table>     # list all indexes on a table

# create a table with columns
CREATE TABLE <table> (<column> VARCHAR(100), <anotherColumn> DATETIME);

# adding a column to a table
ALTER TABLE <table> ADD COLUMN <column> VARCHAR(32);


# list all users
SELECT user, host FROM mysql.user;

# create user
CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';

# grant ALL access to user for all tables
GRANT ALL ON DATABASE.* TO '<username>'@'localhost';

About Author

Christian Unnerstall

Christian Unnerstall, founder of, enjoys designing and building things that look nice and work well, whether it's websites or services within the interwebs. Have questions - feel free to reach out to him. Enjoy

Leave a Reply