您可以配置缓冲池大小 脱机或在服务器运行时。中描述的行为 本节适用于这两种方法。更多信息 关于在线配置缓冲池大小,请参阅在线配置 InnoDB 缓冲池大小。InnoDB
当增加或减少innodb_buffer_pool_size时, 操作以块的形式执行。块大小由 innodb_buffer_pool_chunk_size 配置选项定义,该选项的缺省值为 。有关更多信息,请参阅配置 InnoDB 缓冲池区块大小。128M
缓冲池大小必须始终等于 innodb_buffer_pool_chunk_size innodb_buffer_pool_instances 的倍数或倍数。 如果将innodb_buffer_pool_size配置为 值不等于或等于 innodb_buffer_pool_chunk_size innodb_buffer_pool_instances, 缓冲池大小会自动调整为以下值: 等于或等于 innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances 的倍数。
在以下示例中,innodb_buffer_pool_size 到 ,innodb_buffer_pool_instances 是 设置为 。innodb_buffer_pool_chunk_size 是 ,这是默认值。8G16128M
8G是有效的innodb_buffer_pool_size值 因为是 innodb_buffer_pool_instances=16 * innodb_buffer_pool_chunk_size=128M 的倍数, 这是.8G2G
$> mysqld --innodb-buffer-pool-size=8G --innodb-buffer-pool-instances=16
mysql> SELECT @@innodb_buffer_pool_size/1024/1024/1024;
+------------------------------------------+
| @@innodb_buffer_pool_size/1024/1024/1024 |
+------------------------------------------+
| 8.000000000000 |
+------------------------------------------+
在本例中,innodb_buffer_pool_size 到 ,innodb_buffer_pool_instances 是 设置为 。innodb_buffer_pool_chunk_size 是 ,这是默认值。在这个 case,不是 innodb_buffer_pool_instances=16 innodb_buffer_pool_chunk_size=128M 的倍数, 所以innodb_buffer_pool_size 调整为 ,这是 innodb_buffer_pool_chunk_size innodb_buffer_pool_instances 的倍数。9G16128M9G10G
$> mysqld --innodb-buffer-pool-size=9G --innodb-buffer-pool-instances=16
mysql> SELECT @@innodb_buffer_pool_size/1024/1024/1024;
+------------------------------------------+
| @@innodb_buffer_pool_size/1024/1024/1024 |
+------------------------------------------+
| 10.000000000000 |
+------------------------------------------+
配置 InnoDB 缓冲池区块大小
innodb_buffer_pool_chunk_size可以以 1MB(1048576 字节)为单位增加或减少,但 只能在启动时、命令行字符串或 在 MySQL 配置文件中。
命令行:
$> mysqld --innodb-buffer-pool-chunk-size=134217728
配置文件:
[mysqld]
innodb_buffer_pool_chunk_size=134217728
更改innodb_buffer_pool_chunk_size时,以下条件适用:
如果新的innodb_buffer_pool_chunk_size值 * innodb_buffer_pool_instances 大于当前缓冲池大小,则 缓冲池被初始化,innodb_buffer_pool_chunk_size被截断为 innodb_buffer_pool_size / innodb_buffer_pool_instances。
例如,如果缓冲池初始化时大小 (2147483648 字节)、缓冲池实例和一个块 大小(1073741824 字节),块 size 被截断为等于 innodb_buffer_pool_size / innodb_buffer_pool_instances 的值, 如下图所示:2GB41GB
$> mysqld --innodb-buffer-pool-size=2147483648 --innodb-buffer-pool-instances=4
--innodb-buffer-pool-chunk-size=1073741824;
mysql> SELECT @@innodb_buffer_pool_size;
+---------------------------+
| @@innodb_buffer_pool_size |
+---------------------------+
| 2147483648 |
+---------------------------+
mysql> SELECT @@innodb_buffer_pool_instances;
+--------------------------------+
| @@innodb_buffer_pool_instances |
+--------------------------------+
| 4 |
+--------------------------------+
Chunk size was set to 1GB (1073741824 bytes) on startup but was
truncated to innodb_buffer_pool_size / innodb_buffer_pool_instances
mysql> SELECT @@innodb_buffer_pool_chunk_size;
+---------------------------------+
| @@innodb_buffer_pool_chunk_size |
+---------------------------------+
| 536870912 |
+---------------------------------+
缓冲池大小必须始终等于 innodb_buffer_pool_chunk_size innodb_buffer_pool_instances 的倍数或倍数。 如果更改innodb_buffer_pool_chunk_size,innodb_buffer_pool_size会自动调整为等于或 innodb_buffer_pool_chunk_size innodb_buffer_pool_instances的倍数。 初始化缓冲池时将进行调整。 以下示例演示了此行为:
The buffer pool has a default size of 128MB (134217728 bytes)
mysql> SELECT @@innodb_buffer_pool_size;
+---------------------------+
| @@innodb_buffer_pool_size |
+---------------------------+
| 134217728 |
+---------------------------+
The chunk size is also 128MB (134217728 bytes)
mysql> SELECT @@innodb_buffer_pool_chunk_size;
+---------------------------------+
| @@innodb_buffer_pool_chunk_size |
+---------------------------------+
| 134217728 |
+---------------------------------+
There is a single buffer pool instance
mysql> SELECT @@innodb_buffer_pool_instances;
+--------------------------------+
| @@innodb_buffer_pool_instances |
+--------------------------------+
| 1 |
+--------------------------------+
Chunk size is decreased by 1MB (1048576 bytes) at startup
(134217728 - 1048576 = 133169152):
$> mysqld --innodb-buffer-pool-chunk-size=133169152
mysql> SELECT @@innodb_buffer_pool_chunk_size;
+---------------------------------+
| @@innodb_buffer_pool_chunk_size |
+---------------------------------+
| 133169152 |
+---------------------------------+
Buffer pool size increases from 134217728 to 266338304
Buffer pool size is automatically adjusted to a value that is equal to
or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances
mysql> SELECT @@innodb_buffer_pool_size;
+---------------------------+
| @@innodb_buffer_pool_size |
+---------------------------+
| 266338304 |
+---------------------------+
此示例演示了相同的行为,但 多个缓冲池实例:
The buffer pool has a default size of 2GB (2147483648 bytes)
mysql> SELECT @@innodb_buffer_pool_size;
+---------------------------+
| @@innodb_buffer_pool_size |
+---------------------------+
| 2147483648 |
+---------------------------+
The chunk size is .5 GB (536870912 bytes)
mysql> SELECT @@innodb_buffer_pool_chunk_size;
+---------------------------------+
| @@innodb_buffer_pool_chunk_size |
+---------------------------------+
| 536870912 |
+---------------------------------+
There are 4 buffer pool instances
mysql> SELECT @@innodb_buffer_pool_instances;
+--------------------------------+
| @@innodb_buffer_pool_instances |
+--------------------------------+
| 4 |
+--------------------------------+
Chunk size is decreased by 1MB (1048576 bytes) at startup
(536870912 - 1048576 = 535822336):
$> mysqld --innodb-buffer-pool-chunk-size=535822336
mysql> SELECT @@innodb_buffer_pool_chunk_size;
+---------------------------------+
| @@innodb_buffer_pool_chunk_size |
+---------------------------------+
| 535822336 |
+---------------------------------+
Buffer pool size increases from 2147483648 to 4286578688
Buffer pool size is automatically adjusted to a value that is equal to
or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances
mysql> SELECT @@innodb_buffer_pool_size;
+---------------------------+
| @@innodb_buffer_pool_size |
+---------------------------+
| 4286578688 |
+---------------------------+
更换innodb_buffer_pool_chunk_size时应小心, 因为更改此值可能会增加缓冲区的大小 pool,如上面的示例所示。在更改innodb_buffer_pool_chunk_size之前, 计算对innodb_buffer_pool_size的影响,以确保生成的缓冲池大小为 可以接受。
注意
为避免潜在的性能问题,块数 (innodb_buffer_pool_size / innodb_buffer_pool_chunk_size) 不应超过 1000。