Cara Memeriksa Ukuran indeks MySQL

Perlu untuk diketahui, Ukuran database MySQL yang tercantum di control panel anda merupakan gabungan dari:

  • Data, yaitu data dari database itu sendiri.
  • Index, yang digunakan oleh database untuk mempercepat operasi database.
  • Ruang kosong yang terjadi karena record yang dihapus.

ruang kosong tersebut bisa direklaim dengan cara Optimize database.

Umumnya pada phpMyAdmin memberi informasi ukuran tabel, tetapi ini hanya untuk data, tidak termasuk indeks dan ruang kosong akibat record yang dihapus.

berikut ini adalah cara melihat data & index secara manual melalui terminal

Cara Memeriksa Ukuran indeks MySQL

SELECT CONCAT(table_schema, '.', table_name) db_table,
       CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
       CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024  ), 1), 'M') size,
       CONCAT(ROUND(data_length / ( 1024*1024 ), 1), 'M') data,
       CONCAT(ROUND(index_length / ( 1024*1024 ), 1), 'M') indx,
       ROUND(index_length / data_length, 2) ratio
FROM   information_schema.TABLES
ORDER  BY data_length + index_length DESC LIMIT  30;

outputnya adalah seperti ini

+--------------------------------------------+-------+---------+---------+-------+-------+
| db_table                                   | rows  | size    | data    | indx  | ratio |
+--------------------------------------------+-------+---------+---------+-------+-------+
| gemar_oprek.watchdog                    | 5.74M | 3262.4M | 3171.8M | 90.6M |  0.03 |
| gemar_oprek.cache_form                  | 0.02M | 73.2M   | 71.9M   | 1.2M  |  0.02 |
| gemar_oprek.counter                     | 0.23M | 25.4M   | 18.9M   | 6.5M  |  0.34 |
| gemar_oprek.cache_menu                  | 0.01M | 23.9M   | 23.4M   | 0.5M  |  0.02 |
| gemar_oprek.users                       | 0.02M | 5.9M    | 3.9M    | 2.1M  |  0.53 |
| gemar_oprek.url_alias                   | 0.02M | 2.1M    | 0.8M    | 1.3M  |  1.68 |
| gemar_oprek.cache                       | 0.00M | 1.9M    | 1.9M    | 0.0M  |  0.00 |
| gemar_oprek.cache_update                | 0.00M | 1.1M    | 1.1M    | 0.0M  |  0.00 |
| gemar_oprek.cache_filter                | 0.00M | 1.0M    | 1.0M    | 0.0M  |  0.03 |
| gemar_oprek.node_revisions              | 0.00M | 0.7M    | 0.7M    | 0.0M  |  0.03 |
| gemar_oprek.cache_content               | 0.00M | 0.6M    | 0.6M    | 0.0M  |  0.04 |
| gemar_oprek.menu_router                 | 0.00M | 0.5M    | 0.3M    | 0.1M  |  0.39 |
| gemar_oprek.captcha_sessions            | 0.00M | 0.4M    | 0.3M    | 0.1M  |  0.43 |
| gemar_oprek.search_index                | 0.00M | 0.4M    | 0.1M    | 0.2M  |  1.82 |
| gemar_oprek.cache_views                 | 0.00M | 0.4M    | 0.3M    | 0.0M  |  0.03 |
| gemar_oprek.menu_links                  | 0.00M | 0.3M    | 0.1M    | 0.2M  |  1.30 |
| gemar_oprek.node                        | 0.00M | 0.2M    | 0.1M    | 0.2M  |  2.64 |
| gemar_oprek.views_display               | 0.00M | 0.2M    | 0.2M    | 0.0M  |  0.04 |
| gemar_oprek.variable                    | 0.00M | 0.1M    | 0.1M    | 0.1M  |  0.56 |
| gemar_oprek.search_total                | 0.00M | 0.1M    | 0.1M    | 0.1M  |  1.05 |
| gemar_oprek.system                      | 0.00M | 0.1M    | 0.1M    | 0.0M  |  0.72 |
| gemar_oprek.views_object_cache          | 0.00M | 0.1M    | 0.1M    | 0.0M  |  0.05 |
| gemar_oprek.search_dataset              | 0.00M | 0.1M    | 0.1M    | 0.0M  |  0.07 |
| gemar_oprek.files                       | 0.00M | 0.1M    | 0.0M    | 0.0M  |  0.62 |
| gemar_oprek.sessions                    | 0.00M | 0.1M    | 0.0M    | 0.0M  |  1.23 |
| gemar_oprek.content_node_field_instance | 0.00M | 0.0M    | 0.0M    | 0.0M  |  0.14 |
| gemar_oprek.history                     | 0.00M | 0.0M    | 0.0M    | 0.0M  |  2.60 |
| gemar_oprek.blocks                      | 0.00M | 0.0M    | 0.0M    | 0.0M  |  1.46 |
| gemar_oprek.node_comment_statistics     | 0.00M | 0.0M    | 0.0M    | 0.0M  |  1.53 |
| gemar_oprek.permission                  | 0.00M | 0.0M    | 0.0M    | 0.0M  |  0.12 |
+--------------------------------------------+-------+---------+---------+-------+-------+
30 rows in set (0.02 sec)

Jika Anda ingin melihat ringkasan hanya untuk database, silahkan coba perintah ini:

SELECT count(*) tables,  table_schema dbase,
 concat(round(sum(table_rows) / 1000000, 2), 'M') rows,
 concat(round(sum(data_length + index_length) / (1024 * 1024 ), 1),'M') size,
 concat(round(sum(data_length) / (1024*1024 ), 1), 'M') data,
 concat(round(sum(index_length) / (1024*1024), 1), 'M') indx,
 round(sum(index_length) / sum(data_length), 2) ratio
FROM information_schema.TABLES
GROUP BY table_schema ORDER BY sum(data_length + index_length) DESC;

outputnya adalah seperti ini

+--------+--------------------+-------+---------+---------+--------+-------+
| tables | dbase              | rows  | size    | data    | indx   | ratio |
+--------+--------------------+-------+---------+---------+--------+-------+
|    114 | gemar_oprek     | 6.06M | 3403.3M | 3299.5M | 103.8M |  0.03 |
|     33 | information_schema | NULL  | 0.0M    | 0.0M    | 0.0M   |  NULL |
+--------+--------------------+-------+---------+---------+--------+-------+
2 rows in set (0.03 sec)

NB: ilustrasi yang digunakan adalah database drupal 😀

Write a Comment

Your email address will not be published.

three × one =

%d bloggers like this: