MySQL: How to show the schema of a MySQL database table

MySQL table/schema FAQ: How do I show a database table schema in a MySQL database?

Short answer: To show the schema for a MySQL database table, use the MySQL desc command. You issue this command from the MySQL client command line prompt, like this:

mysql> desc orders;

A complete MySQL “show tables” example

Longer answer: You need to log into your MySQL database, select a database to use, and then issue the desc command. For instance, assuming you want to see the schema of a table named orders in a database named restaurant, use these commands from the mysql client (MySQL command line) after logging into your MySQL database:

mysql -u root -p
[enter password here]

mysql> use restaurant;

mysql> desc orders;

The first command (use restaurant) tells MySQL that you want to work in that database, and the second command (desc orders) shows the schema of the MySQL table named orders.

When I run the MySQL desc command on one of my sample MySQL database tables named customers, I see output that looks like this:

mysql> desc customers;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment | 
| name  | varchar(20)      | NO   |     | NULL    |                | 
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.14 sec)