MySQL Cheat-Sheet

I grabbed this from the Web years ago I don’t remember where. Saved it for my own use.

To login (from unix shell) use -h only if needed.

# [mysql dir]/bin/mysql -h hostname -u username -p password

Login to MySQL while in linux shell

# mysql -u root -p

Exit MySQL terminal back to the default terminal.

mysql> exit

Create a database.

mysql> create database [databasename];

List all databases on the server.

mysql> show databases;

Switch to a database.

mysql> use [db name];

To see all the tables in the db.

mysql> show tables;

To see table’s field formats.

mysql> describe [table name];

To delete a db.

mysql> drop database [database name];

To delete a table.

mysql> drop table [table name];

Show all data from a table.

mysql> SELECT * FROM [table name];

To return columns and column information.

mysql> show columns from [table name];

Show particular rows with the given value.

mysql> SELECT * FROM [table name] WHERE [field name] = "value";