Watch our 3-minute video to find out how you can learn MySQL with a live instructor.
Additional Resources

Show Database Information

In this lesson of the MySQL tutorial, you will learn...
  1. Show database, table and index information.
  2. Using INFORMATION-SCHEMA.

In this lesson of the MySQL tutorial, we learn how to see information about storage elements in MySQL.

SHOW and DESCRIBE Statements

Using Table-Related SHOW Statements

We can use the SHOW COLUMNS statement to lists the columns in a table, along with information about the columns.

Syntax
SHOW [FULL] COLUMNS FROM <table name> [FROM <database name>] [LIKE '<value>']

FULL keyword shows more complete information about each column, and LIKE can be used to limit the values returned.

Code Sample: ShowDBInfo/Demos/ShowColumns.sql

USE sakilakubili;
SHOW COLUMNS FROM film_review;
SHOW COLUMNS FROM user FROM mysql LIKE 'max%';

You can also retrieve construction information of a table by using a SHOW CREATE TABLE statement, which shows the actual table definition.

Code Sample: ShowDBInfo/Demos/ShowCreateTable.sql

USE sakilakubili;
SHOW CREATE TABLE film_review;

Note::The entire results may not fit on the screen and what you see depends on your system.

The next statement displays a list of indexes in a table. The output SHOW INDEX statement is shown below.

Code Sample: ShowDBInfo/Demos/ShowIndex.sql

USE sakilakubili;
SHOW INDEX FROM film_review;
SHOW INDEX FROM user FROM mysql;
+-------------+------------+---------+-------------+-----------
| Table       | Non_unique | Key_name| Seq_in_index| Column_name
 Collation | Cardinality | ... | Null | Index_type | Comment |
+-------------+------------+---------+-------------+-----------
| film_review |          0 | PRIMARY |            1| review_id  
A         |            0 | ... |      | BTREE      |         |
+-------------+------------+---------+-------------+-----------
1 row in set (0.00 sec)

The next statement is the SHOW TABLES statement, which displays a list of tables in the current database or a specified database.

Code Sample: ShowDBInfo/Demos/ShowDBTables.sql

USE sakilakubili;
SHOW TABLES;
SHOW TABLES FROM mysql LIKE 'time%';
+------------------------+
| Tables_in_sakilakubili |
+------------------------+
| film_review            |
+------------------------+
1 row in set (0.00 sec)

Using DESCRIBE Statement

DESCRIBE is another statement useful for viewing table information. The following example shows a DESCRIBE statement that returns information about all columns in the user table that end with "priv":

DESCRIBE user '%priv';

Code Sample: ShowDBInfo/Demos/ShowDatabases.sql

SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| sakila             |
| test               |
+--------------------+
4 rows in set (0.11 sec)

Code Sample: ShowDBInfo/Demos/ShowCreateDatabase.sql

SHOW CREATE DATABASE sakilakubili;

As we work through this courseware, these statements will be used repeatedly to make our lives easier.

INFORMATION_SCHEMA Tables

INFORMATION_SCHEMA is the information database in MySQL server that provides access to database metadata, or data about the data, such as a table name, the constraints on a column, or access privileges. The same informationis also referred to as data dictionary and system catalog.

Here is an example to list all the tables in sakila database, in reverse alphabetical order:

Code Sample: ShowDBInfo/Demos/InfoTables.sql

SELECT table_name, table_type, engine
FROM information_schema.tables
WHERE table_schema = 'sakila'
ORDER BY table_name DESC;
+----------------------------+------------+--------+
| table_name                 | table_type | engine |
+----------------------------+------------+--------+
| actor                      | BASE TABLE | InnoDB |
| actor_info                 | VIEW       | NULL   |
| ...                        |            |  ...   |
| store                      | BASE TABLE | InnoDB |
| studio                     | BASE TABLE | InnoDB |
+----------------------------+------------+--------+
26 rows in set (0.20 sec)

Note:Users prefer to use both SHOW and INFORMATION_SCHEMA

The following example lists the various tables found in INFORMATION_SCHEMA.

Code Sample: ShowDBInfo/Demos/ShowInfoSchemaTables.sql

SELECT table_name FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = 'INFORMATION_SCHEMA'
AND table_name LIKE '%';

Showing Databases

Here is a read of another table which shows that the following statements are equivalent:

SELECT SCHEMA_NAME AS `Database`
 FROM INFORMATION_SCHEMA.SCHEMATA
 [WHERE SCHEMA_NAME LIKE '
wild
']

SHOW DATABASES [LIKE '
wild
']

Code Sample: ShowDBInfo/Demos/InfoDatabases.sql

SELECT SCHEMA_NAME AS `Database`
FROM INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME LIKE 'sakila%';

SHOW DATABASES LIKE 'sakila%';

Show Database Information Conclusion

This lesson covered the mechanisms to create a database and some components.

To continue to learn MySQL go to the top of this page and click on the next lesson in this MySQL Tutorial's Table of Contents.
Last updated on 2008-12-16

Use of http://www.learn-mysql-tutorial.com (Website) implies agreement to the following:

Copyright Information

All pages and graphics on Website are the property of Webucator, Inc. unless otherwise specified.

None of the content on Website may be redistributed or reproduced in any way, shape, or form without written permission from Webucator, Inc.

No Printing or saving of pages or content on Website

This content may not be printed or saved. It is for online use only.


Linking to Website

You may link to any of the pages on Website; however, you may not include the content in a frame or iframe without written permission from Webucator, Inc.


Warranties

Website is provided without warranty of any kind. There are no guarantees that use of the site will not be subject to interruptions. All direct or indirect risk related to use of the site is borne entirely by the user. All code and explanations provided on this site are provided without warranties to correctness, performance, fitness, merchantability, and/or any other warranty (whether expressed or implied).


For individual private use only

You agree not to use this online manual to deliver or receive training. If you are delivering or attending a class that is making use of this online manual, you are in violation of our terms of service. Please report any abuse to courseware@webucator.com. If you would like to deliver or receive training using this manual, please fill out the form at http://www.webucator.com/Contact.cfm