mysql key buffer_MySQL的key_buffer_size参数

先来看看document对这个参数的解释:

缓存myisam表的索引块大小,可以被所有进程所共享。当设置key_buffer_size,操作系统不会马上分配key_buffer_size设置的值,而是在需要的时候,再分配的。可以设置多个key_buffer,当设置不是默认key_buffer为0时,mysql会把缓存的索引块移到默认的key_buffer中去并删除不再使用的索引块。Myisam表中只能cache索引块,不能cache数据块。

原本描述:

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.

The maximum allowable setting for key_buffer_size is 4GB on 32-bit platforms. As of MySQL 5.0.52, values larger than 4GB are allowed for 64-bit platforms (except 64-bit Windows, for which large values are truncated to 4GB with a warning). The effective maximum size might be less, depending on your available physical RAM and per-process RAM limits imposed by your operating system or hardware platform. The value of this variable indicates the amount of memory requested. Internally, the server allocates as much memory as possible up to this amount, but the actual allocation might be less.

Increase the value to get better index handling (for all reads and multiple writes) to as much as you can afford. Using a value that is 25% of total memory on a machine that mainly runs MySQL is quite common. However, if you make the value too large (for example, more than 50% of your total memory) your system might start to page and become extremely slow. MySQL relies on the operating system to perform file system caching for data reads, so you must leave some room for the file system cache. Consider also the memory requirements of other storage engines.

1、建立缓存索引 :

mysql> set global key_buffer_1.key_buffer_size=8384512;

Query OK, 0 rows affected (0.01 sec)

mysql> set global key_buffer_2.key_buffer_size=8384512;

Query OK, 0 rows affected (0.01 sec)

2、把指定表放到key buffer中

mysql> cache index t1,t2 in key_buffer_1;

+————+——————–+———-+———-+

| Table | Op | Msg_type | Msg_text |

+————+——————–+———-+———-+

| luoxuan.t1 | assign_to_keycache | status | OK |

| luoxuan.t2 | assign_to_keycache | status | OK |

+————+——————–+———-+———-+

2 rows in set (0.00 sec)

3、预先装载表的索引块

mysql> load index into cache t1,t2;

+————+————–+———-+———-+

| Table | Op | Msg_type | Msg_text |

+————+————–+———-+———-+

| luoxuan.t1 | preload_keys | status | OK |

| luoxuan.t2 | preload_keys | status | OK |

+————+————–+———-+———-+

2 rows in set (0.00 sec)

下面我们来看一下,如果计算命中率及key buffer的使用率

Cache命中率:

100 – ( (Key_reads * 100) / Key_read_requests )

Key buffer的使用率

100 – ( (Key_blocks_unused * key_cache_block_size) * 100 / key_buffer_size )

觉得文章有用?立即:

和朋友一起 共学习 共进步!

猜您喜欢

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值