Query Cek Size 1 / Single Database Di MySQL
Query ini akan mengkalkulasi berapa besar size untuk 1 database / single database di MySQL server. Sesuaikan nama database dengan database yang akan di kalkulasi.
SELECT table_schema "Database Name", SUM( data_length + index_length)/1024/1024 "Database Size (MB)" FROM information_schema.TABLES where table_schema = 'mydb';
+---------------+--------------------+ | Database Name | Database Size (MB) | +---------------+--------------------+ | mydb | 0.15625000 | +---------------+--------------------+ 1 row in set (0.04 sec)
Query Cek Semua Size Database Di MySQL
Query ini akan mengkalkulasikan semua database yang tersedia di database server anda.
SELECT table_schema "Database Name", SUM(data_length+index_length)/1024/1024 "Database Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;
+--------------------+--------------------+ | Database Name | Database Size (MB) | +--------------------+--------------------+ | demodb | 0.15625000 | | information_schema | 0.00976563 | | mydb | 0.15625000 | | mysql | 0.81098557 | | performance_schema | 0.00000000 | +--------------------+--------------------+ 5 rows in set (0.01 sec)
Query Cek 1 Table / Single Table Di Database MySQL
Query ini akan mengkalkulasikan size tabel anda dengan mendifinisikan lebih spesifik nama database dan tabel anda.
SELECT table_name "Table Name", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2) "Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "mydb" AND table_name ="table_one";
+---------------------+------------+-----------------+ | Table Name | Rows Count | Table Size (MB) | +---------------------+------------+-----------------+ | archive_one | 8 | 0.09 | +---------------------+------------+-----------------+ 1 row in set (0.00 sec)
Cek Semua Size Table di Database MySQL
Query ini akan mengkalkulasikan jumlah baris beserta size di semua table dan di 1 database
SELECT table_name "Table Name", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2) "Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "mydb";
+----------------------+------------+-----------------+ | Table Name | Rows Count | Table Size (MB) | +----------------------+------------+-----------------+ | table_one | 8 | 0.09 | | table_two | 0 | 0.02 | | table_three | 0 | 0.02 | | table_four | 174 | 0.03 | +----------------------+------------+-----------------+ 4 rows in set (0.00 sec)
semoga bermanfaat 😊