wiki/docs/MySQL/size.md
Ludovic Cartier 3e0a7572e6 go to mkdocs
2024-08-09 18:26:06 +02:00

1.1 KiB

categories: mysql title: Taille des bases de données et tables

Obtenir la taille de toutes les bases de données présentes sur le serveur :

SELECT table_schema AS 'DB Name', ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS 'DB Size in MB' FROM information_schema.tables GROUP BY table_schema;

Obtenir la taille d'une base en particulier :

SELECT table_schema AS 'DB Name', ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS 'DB Size in MB' FROM information_schema.tables WHERE table_schema = '##DBNAME##' GROUP BY table_schema;

Obtenir la taille de toutes les tables d'un base de données spécifique :

SELECT TABLE_NAME AS `Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)` FROM information_schema.TABLES WHERE TABLE_SCHEMA = "<DBNAME>" ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC;

Obtenir la taille de toutes les tables de toutes les bases de données :

SELECT TABLE_SCHEMA AS `Database`, TABLE_NAME AS `Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)` FROM information_schema.TABLES ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC;