设置这个变量可以一次性为键缓存区分配所有指定的空间。操作系统并不会真的立刻分配内存,而是到使用时才分配内存。key_buffer_size只对MyISAM表起作用。MyISAM的表使用键高速缓存来缓存索引,这个键高速缓存的大小则通过 key-buffer-size 参数来设置。如果应用系统中使用的表以MyISAM存储引擎为主,则应该适当增加该参数的值,以便尽可能的缓存索引,提高访问的速度。https://www.cndba.cn/hbhe0316/article/22613https://www.cndba.cn/hbhe0316/article/22613
官网连接:https://dev.mysql.com/doc/refman/8.0/en/myisam-key-cache.html
To control the size of the key cache, use the key_buffer_size system variable. If this variable is set equal to zero, no key cache is used. The key cache also is not used if the key_buffer_size value is too small to allocate the minimal number of block buffers (8).https://www.cndba.cn/hbhe0316/article/22613
1.查看当前值
mysql> SHOW VARIABLES LIKE '%key_buffer_size%';
+-----------------+---------+
| Variable_name | Value |
+-----------------+---------+
| key_buffer_size | 8388608 |
+-----------------+---------+
1 row in set (0.00 sec)
2.设置global全局的key_buffer_size值https://www.cndba.cn/hbhe0316/article/22613https://www.cndba.cn/hbhe0316/article/22613
mysql> set global key_buffer_size=16*1024*1024;
Query OK, 0 rows affected (0.01 sec)
3.设置/etc/my.cnf文件https://www.cndba.cn/hbhe0316/article/22613
[root@mysql57 ~]# cat /etc/my.cnf | grep -i key-buffer-size
key-buffer-size= 32M
[root@mysql57 ~]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!
查看是否设置成功https://www.cndba.cn/hbhe0316/article/22613https://www.cndba.cn/hbhe0316/article/22613
mysql> SHOW VARIABLES LIKE '%key_buffer_size%';
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| key_buffer_size | 33554432 |
+-----------------+----------+
1 row in set (0.00 sec)
版权声明:本文为博主原创文章,未经博主允许不得转载。
MYSQL