Get the largest tables in Mysql database

background

  • When optimizing the mysql database, we often need to observe which tables in the database are relatively large, so how can we quickly obtain the relatively large tables in the current database?

solution

  • code directly
SELECT
	table_name,
	table_size/1024/1024
FROM
	(
		SELECT
			table_name,
			data_length + index_length table_size
		FROM
			information_schema. TABLES
	) t1
ORDER BY
	table_size DESC
LIMIT 10;

This example is to query the ten largest tables in the currently opened data. The size unit of the table is M. If you want to get more tables, you only need to modify the limit parameter.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325340907&siteId=291194637