MYSQL statements for display database information’s:

 In this blog post, we list out some mysql functions for processing the database informations like databases linked in the mysql, its name and describe the table and its properties.

Some other functions like display time,day.

First, the list of databases used in the mysql can be expressed using the code ‘SHOW DATABASES’.

mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| my_database        |

| mysql              |

| performance_schema |

| sakila             |

| sys                |

| world              |

+--------------------+

7 rows in set (1.602 sec)

Second, set a particular database for your SQL project.

mysql> USE MY_DATABASE;

Database changed

mysql> Describe students;

+-------+-------------+------+-----+---------+----------------+

| Field | Type        | Null | Key | Default | Extra          |

+-------+-------------+------+-----+---------+----------------+

| id    | int         | NO   | PRI | NULL    | auto_increment |

| name  | varchar(50) | YES  |     | NULL    |                |

| age   | int         | YES  |     | NULL    |                |

+-------+-------------+------+-----+---------+----------------+

3 rows in set (0.291 sec)

Next, the tables associated with the database is listed as follows.

mysql> SHOW TABLES;

+-----------------------+

| Tables_in_my_database |

+-----------------------+

| students              |

+-----------------------+

1 row in set (0.181 sec)

Here, a particular table structure is displayed.

mysql> SHOW CREATE TABLE STUDENTS;

+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Table    | Create Table                                                                                                                                                                                                                        |

+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| students | CREATE TABLE `students` (

  `id` int NOT NULL AUTO_INCREMENT,

  `name` varchar(50) DEFAULT NULL,

  `age` int DEFAULT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |

+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.304 sec)

It displays the current time of the system.

mysql> SELECT NOW();

+---------------------+

| NOW()               |

+---------------------+

| 2026-02-04 11:50:31 |

+---------------------+

1 row in set (0.008 sec)

You can calculate expressions in mysql directly by giving it in the prompt.

mysql> SELECT 2+7;

+-----+

| 2+7 |

+-----+

|   9 |

+-----+

1 row in set (0.024 sec)

Expression evaluation and displaying the current date at the same time as follows.

mysql> SELECT 2+7,CURDATE();

+-----+------------+

| 2+7 | CURDATE()  |

+-----+------------+

|   9 | 2026-02-04 |

+-----+------------+

1 row in set (0.013 sec)

These are the basic queries to display the database information’s. Hope, these queries are useful to you. Keep coding!!!

Comments

Popular posts from this blog

How to create a XML DTD for displaying student details

Symmetric Encryption in java

Java NIO examples to illustrate channels and buffers.