What if you forget the name of a database or table, or the structure of a given table (for example, what is its column called)? MySQL solves this problem by providing several statements of information about the database and its supported tables.
You've seen show DATABASES, which lists the databases managed by the server. To find out which database is currently selected, use the DB () function:
mysql> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| menagerie |
+------------+
If you have not selected any database, the result is empty.
To find out what tables the current database contains (for example, when you can't determine the name of a table), use this command:
mysql> SHOW TABLES;
+---------------------+
| Tables in menagerie |
+---------------------+
| event |
| pet |
+---------------------+
If you want to know the structure of a table, the describe command is very helpful; It displays information about each column of a table:
mysql> DESCRIBE pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
field displays the column name, type is the data type of the column, and NULL indicates whether the column can contain null values, and the key shows whether the column is indexed and default specifies the column defaults.
If you have an index on a table, show the index from Tbl_name generates information about them.