In some documents I found that we can assign key_buffer_size to myisam table. This also includes the following steps:

SET GLOBAL myisam_table.key_buffer_size = 4194304;

CACHE INDEX test.myisam_table IN myisam_table;

LOAD INDEX INTO CACHE test.myisam_table;

This command worked fine.

But how can I see the MyISAM table that is taking the key_buffer_size not the global one?

Is there any other MySQL engine that supports something similar?

2 Answers 2


In your question, you gave the correct syntax for setting up a dedicated key cache (See LOAD INDEX INTO CACHE)

I wrote about this before

Once you assign one or more tables to a dedicated key cache and run LOAD INDEX INTO CACHE:

  • the cached indexes will
  • all you can tell is what tables are not going to the default key cache

If you want make sure of what is cached is not too excessive, to the following:

STEP01) Run this query

SUBSTR(' KMG',IF(PowerOf1024<0,0,
recommended_key_buffer_size FROM
FROM (SELECT SUM(index_length) KBS1
FROM information_schema.tables
table_schema NOT IN ('information_schema','mysql')) AA ) A,
(SELECT 2 PowerOf1024) B;

This will count how big (in MB) the default key cache should be in order to HOLD ALL MyISAM INDEX PAGES.

STEP02) Assign the recommended number

Suppose the query from STEP01 is 5G.

  • If your machine only only has 4GB or RAM, obviously don't assign it. Use half the recommended value (2G).
  • If your machine has 10G, go ahead and assign 5G for key cache

So in the first case


in the second case


STEP03) service mysql restart

STEP04) Run your production system for a week

STEP05) Run this query

SHOW GLOBAL STATUS LIKE 'Key_blocks_used';
SHOW GLOBAL STATUS LIKE 'key_cache_block_size';

Whatever those two numbers return, multiply together and divide by 1048576. That will give you how many MB of space is used in the MyISAM key cache. Multiply that number by 1.05 and round it to the nearest whole number. Whatever that number is, that's the number you use as the final value for key_buffer_size.

You will have to do these 5 Steps again in 6 months to make sure the working set for MyISAM data's indexes has the safest value. It may also reveal if you need to expand RAMon the DB Server.

  • This looks helpful, but I had a problem with step 5. I ran the queries and it looks like you need to use SHOW GLOBAL VARIABLES LIKE 'key_cache_block_size';. "VARIABLES" rather than "STATUS".
    – codewaggle
    Jan 13, 2013 at 10:45

You can't give this value for a particular table this value indicates Index blocks for MyISAM tables are buffered and are shared by all threads. key_buffer_size is the size of the buffer used for index blocks. The key buffer is also known as the key cache.


InnoDB engine type does support similar option called innodb_buffer_pool_size

The size in bytes of the memory buffer InnoDB uses to cache data and indexes of its tables. The default value is 8MB. The larger you set this value, the less disk I/O is needed to access data in tables. On a dedicated database server, you may set this to up to 80% of the machine physical memory size. However, do not set it too large because competition for physical memory might cause paging in the operating system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.