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:
- Size of all databases in megabytes.
- Size of all databases in gigabytes.
- The size of the tables in the database in megabytes.
- 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;
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;
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;
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;
Thank you all, I hope my article was of some help to you.