MySQL MariaDB

How to Check Query Time in MySQL?

While working on a MySQL server, the user can design and create databases, maintain them, recover, and manage backups, as well as measure performance. More specifically, measuring the performance of the databases is linked with time. So, to measure the database’s performance, developers need to measure the query time.

This blog will provide the method for checking query time in MySQL.

How to Check Query Time in MySQL?

To check query time in MySQL, first, open and connect the Windows terminal with the MySQL server. Then, view all and change the database. Next, set the “profiling” value to “1”. After that, show tables and display their content. Lastly, run the “SHOW PROFILES;” command to list all executed queries time.

Step 1: Access MySQL Server

First, open the Windows terminal and run the “mysql” command:

mysql -u root -p

According to provided output, the terminal is connected with the MySQL server successfully:

Step 2: Display Database

Then, view all the available databases by executing the “SHOW” command with the “DATABASES” option:

SHOW DATABASES;

From the given output, selected “testdb” database is selected for further process:

Step 3: Set Profile Value

Now, assign the value to the “profiling” variable by running the “SET” command:

SET profiling = 1;

Step 4: Change Database

To change the database, execute the “USE” command:

USE testdb;

Step 5: Display Tables

Next, run the following query to list all the existing tables:

SHOW TABLES;

According to the below-given output, the current database contains a single table named “testingtable1”:

Step 6: Show Table Content

Execute the “SELECT” command to view the table records:

SELECT * FROM testingtable1;

Step 7: Check Query Time

Finally, check all the above-executed queries time, use the “SHOW” command with the “PROFILES” option:

SHOW PROFILES;

In the above-stated command, the “PROFILES” option is used to show detailed information about each statement:

It can be observed that the previously used queries are displayed in the table with their executed time duration.

Conclusion

To check query time in MySQL, first, open and connect the Windows terminal with the MySQL server. Then, view all and change the database. After that, show tables and display their content. Next, set the “profiling” value to “1” and perform different queries. Finally, execute the “SHOW PROFILES;” command to list all executed queries’ time duration. This blog illustrated the method for checking query time in MySQL.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.