MySQL table schema - how to show the schema of a MySQL 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)

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.