How do I view the Mysql database size with the SQL command

  • 2020-05-24 06:21:00
  • OfStack

To know the size of each database, follow these steps:
1. Enter information_schema database (store information of other databases)
use information_schema;

2. Query the size of all data:
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;

3. View the size of the specified database:
For example, look at the size of the database home
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';

View the size of a table in the specified database
For example, look at the size of the members table in the database home
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';


Related articles: