Skip to content
CODE THE PIXEL
On this page
Misc

Print MySQL Table Description Using Command Line

Asyraf Wahi Anuar Updated 3 min read

This tutorial will show how to access MySQL databases and tables using the command line interface

This tutorial may be outdated

It was last reviewed 4 years ago. Some steps may differ in newer versions.

The database is a crucial back-end component of software applications. Technically, all collected data is stored and managed in the database. When a user login into a web application, or completes an online transaction, a database system records the information in a structured manner in the background. MySQL is a relational database management system (RDBMS), which means that instead of a single repository, it keeps records in several, independent, and highly codified tables. There are numbers of application that is designed to manage MySQL databases and table. However, this tutorial will show how to access MySQL databases and tables using the command line interface.

The CLI Command

Execute your command prompt. This tutorial uses Windows Power Shell in Windows 11 and XAMPP. The XAMPP application is installed at c:/xampp. To connect to the MySQL database, change the read directory as shown below (depending on your web server installation directory):

Terminal
cd c:/xampp/mysql/bin

Once the directory changed, execute the following command to connect into the database:

Terminal
mysql -u root -p -h 127.0.0.1

Command explaination:
-u = user (default: root)
-p = password (if null, left it blank with -p)
-h = host (localhost/127.0.0.1/your webserver IP)

Once connected to the MySQL, you can execute the following command to list all available databases:

HTML
show databases;

To select and use a database (eg: edms), use the following command.

HTML
use edms;

Execute the following command to list all available tables in edms database

HTML
show tables;

If you need the table attributes, use the following command to describe the table field, type, null, key, default and extra.

HTML
describe edms.logs;

This is the example of table description.

HTML
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(11)      | NO   | PRI | NULL    | auto_increment |
| user_id   | int(11)      | YES  |     | NULL    |                |
| action    | varchar(255) | YES  |     | NULL    |                |
| useragent | varchar(256) | YES  |     | NULL    |                |
| os        | varchar(255) | YES  |     | NULL    |                |
| ip        | varchar(50)  | YES  |     | NULL    |                |
| host      | varchar(255) | YES  |     | NULL    |                |
| referrer  | varchar(255) | NO   |     | NULL    |                |
| status    | int(1)       | YES  |     | 1       |                |
| created   | datetime     | YES  |     | NULL    |                |
| modified  | datetime     | YES  |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+

Now you should be able to connect to the MySQL database and print the table description.

Did this tutorial help?

215 readers found this helpful

Comments

No comments yet. Questions about this tutorial are welcome here: the answer helps the next reader too.

Leave a comment

Markdown works: `code`, ``` blocks, **bold**, links.

First comments are reviewed before they appear.

Misc

Git Tutorial: Uploading a Project to GitHub and Collaborating with Others

Version control is essential for developers, and Git is a powerful tool that helps manage project changes efficiently. GitHub, a popular platform built on Git, not only hosts repositories but also facilitates collaboration among developers worldwide. In this tutorial, we will explore the process of...

4 min read

Misc

Git Pull Error in cPanel

Solving cPanel Git pull error by using the composer install no dev optimized autoloader

2 min read