<pre name="code" class="sql">mysql> show variables like '%cache_size%';
+----------------------------+----------------------+
| Variable_name | Value |
+----------------------------+----------------------+
| binlog_cache_size | 131072 |
| binlog_stmt_cache_size | 32768 |
| host_cache_size | 654 |
| innodb_ft_cache_size | 8000000 |
| innodb_ft_total_cache_size | 640000000 |
| max_binlog_cache_size | 18446744073709547520 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| metadata_locks_cache_size | 1024 |
| query_cache_size | 1048576 |
| thread_cache_size | 18 |
+----------------------------+----------------------+
max_binlog_cache_size :(默认4GB, 也是最大值) 用于限制用于 cache 多个语句事务的总量。
如果一个事务大于这个值,它会失败回滚。
Max_binlog_cache_size: 默认值是18446744073709547520,这个值很大,够我们使用的了。此参数和binlog_cache_size相对应,代表binlog所能使用的cache最大使用大小。如果系统中事务过多,而此参数值设置有小,则会
报错。
The Binlog_cache_use status variable shows the number of transactions that used this buffer (and possibly a temporary file) for storing statements.
The Binlog_cache_disk_use status variable shows how many of those transactions actually had to use a temporary file.
These two variables can be used for tuning binlog_cache_size to a large enough value that avoids the use of temporary files.
max_binlog_size = 512M
binlog_cache_size = 128K
Binlog_cache_use 显示 事务的数量被用于这个buffer(也可能是临时文件)用于存储语句。
Binlog_cache_disk_use 显示多少的事务数 必须得使用临时文件
这两个变量能用于调整binlog_cache_size 到一个足够大的值来避免使用临时文件
max_binlog_size = 512M
The server also creates a new binary log file automatically after the current log's size reaches max_binlog_size. A binary log file may become larger than max_binlog_size if you are using large
transactions because a transaction is written to the file in one piece, never split between files.
server 也会自动的创建一个新的binary log 文件,在当前的log 大小达到max_binlog_size 的时候, 一个binary log 文件可能会大于max_binlog_size 如果你要使用大的
事务 因为一个事务 会被写入到一个文件中,不会分隔到几个文件。
参数:binlog_cache_size 就是满足以上两点的:一个事务,在没有提交(uncommitted)的时候,产生的日志,记录到Cache中;等到事务提交(committed)需要提交的时候,则把日志持久化到磁盘
当一个thread 开始处理事务,它分配一个binlog_cache_size 的buffer 来buffer 语句。
如果语句的大小大于这个值, thread 打开一个临时的文件来存储transaction,临时文件被删除在thread 结束后。
mysql> show status like 'binlog_%';
+----------------------------+---------+
| Variable_name | Value |
+----------------------------+---------+
| Binlog_cache_disk_use | 445 |
| Binlog_cache_use | 9019263 |
可以看到用到了临时文件,需要加大binlog_cache_size