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):
cd c:/xampp/mysql/bin
Once the directory changed, execute the following command to connect into the database:
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:
show databases;
To select and use a database (eg: edms), use the following command.
use edms;
Execute the following command to list all available tables in edms database
show tables;
If you need the table attributes, use the following command to describe the table field, type, null, key, default and extra.
describe edms.logs;
This is the example of table description.
+-----------+--------------+------+-----+---------+----------------+
| 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.