MySQL: Find Out Which Table is Consuming Resources

MySQL: Find Out Which Table is Consuming Resources

To find out which tables are consuming resources in a MySQL database, you can use the INFORMATION_SCHEMA.TABLES table. This table contains information about all tables in the database, including the size of the tables, the number of rows, and the number of disk reads and writes.

To find out which tables are consuming resources in a MySQL database, follow these steps:

  1. Connect to the MySQL server using the mysql utility. You can use the mysql utility to connect to the MySQL server as the root user or another user with the appropriate privileges. For example:
r‮ refe‬to:lautturi.com
mysql -u root -p

Enter the password for the user account when prompted.

  1. Select the database that contains the tables you want to check. You can use the USE command to select the database:
mysql> USE database_name;

Replace database_name with the name of the database that contains the tables you want to check.

  1. Query the INFORMATION_SCHEMA.TABLES table to get information about the tables in the database. You can use the following query to get information about the tables in the database, sorted by the number of disk reads:
mysql> SELECT TABLE_NAME, TABLE_ROWS, DATA_LENGTH, INDEX_LENGTH, TABLE_TYPE, ENGINE, (DATA_READS + INDEX_READS) as TOTAL_READS, (DATA_WRITES + INDEX_WRITES) as TOTAL_WRITES FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'database_name' ORDER BY TOTAL_READS DESC;

Replace database_name with the name of the database you want to check. This query will show the name, size, and number of reads and writes for each table in the database, sorted by the number of disk reads.

  1. Disconnect from the MySQL server. Once you have finished running the query, you can disconnect from the MySQL server by typing exit at the MySQL prompt:
mysql> exit
Created Time:2017-10-30 10:17:51  Author:lautturi