Home / Review Insights

MySQL to view the database size

time:2025-02-07 16:02:34 Review Insights

 mysql to check the database size

In MySQL, you can view the database size in the following ways:

1. Query the size of the entire database: You can use the following code: 'select concat(round(sum(sum(DATA_LENGTH/1024/1024),2),\'MB\') as data from information_schema. TABLES`。 This will return the size of the entire database, converted to MB.

2. Query the size of a database: You can use the following code: 'select concat(round(sum(DATA_LENGTH/1024/1024),2),\'MB\') as data from information_schema. TABLES where table_schema = \'testdb\'`。 This will return the size of the specified database.

3. To check the size of a table in the database, you can use the following code: 'select concat(round(sum(sum(DATA_LENGTH/1024/1024),2),\'MB\') as data from information_schema. TABLES where table_schema = \'testdb\' and table_name = \'test_a\'`。 This returns the size of a table in the specified database.

4. Check the table starting with test in the mysql database, all storage sizes: you can use the following code: 'select concat(round(sum(sum(DATA_LENGTH/1024/1024),2),\'MB\') as data from information_schema. TABLES where table_schema = \'testdb\' and table_name like \'test%\'`。 This will return the size of all tables in the specified database that start with test.

All of the above queries require the use of a information_schema database, which holds information from other databases.

《MySQL to view the database size》 This does not represent the views of this website. If there is any infringement, please contact us to delete it.

Recommend

Ranking

Tech Beyond