MariaDB Database size, tables

  • Last update: Apr 3, 2024
  • Views: 33
  • Author: Admin
MariaDB Database size, tables

Hello colleagues.

In today's short article, I want to give you some useful scripts for viewing the size of a database as an example. I will show examples that will show the size of the database in megabytes and gigabytes.

 

Article content:

  1. Size of all databases in megabytes.
  2. Size of all databases in gigabytes.
  3. The size of the tables in the database in megabytes.
  4. The size of the tables in the database in gigabytes.

 

1. Size of all databases in megabytes.

mariadb> SELECT table_schema AS "Database", 
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema;

mariadb_database_size


 

2. Size of all databases in gigabytes.

mariadb> SELECT table_schema AS "Database", 
ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS "Size (GB)" 
FROM information_schema.TABLES 
GROUP BY table_schema;

mariadb_database_size


 

3. The size of the tables in the database in megabytes.

mariadb> SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "test"
ORDER BY (data_length + index_length) DESC;

mariadb_database_size


 

4. The size of the tables in the database in gigabytes.

mariadb> SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024 / 1024), 2) AS "Size (GB)"
FROM information_schema.TABLES
WHERE table_schema = "test"
ORDER BY (data_length + index_length) DESC;

mariadb_database_size


 

Thank you all, I hope my article was of some help to you.

SIMILAR ARTICLES