mysql binlog index 文件内容

binlog.index文件内容

记录了binlog文件的具体路径,在MySQL启动时,会找到binlog.index文件,然后读取它里面的条目,从而读取binlog文件。

cat /mysql/3306/data/master.index

/mysql/3306/data/master.000001
/mysql/3306/data/master.000002
/mysql/3306/data/master.000003
./master.000004
./master.000005
  1. binlog文件的路径可以是相对路径,也可以是绝对路径
  2. 如果是绝对路径,当文件被移动到其它地方时,只能手动修改对应的路径,否则MySQL在启动时,会报找不到文件路径的错误

设置binlog文件路径

可以在 my.cnf中设置binlog的文件路径

[mysqld]
log-bin=master

或设置为绝对路径

[mysqld]
log-bin=/mysql/3306/data/master

参数 log-bin身兼多职

设置后生效多个参数

  1. 表示启用 binlog功能
  2. 同时设置 binlog.index的文件名
  3. 同时设置binlog的文件名
show variables like '%log_bin%';
+---------------------------------+----------------------------------------------+
| Variable_name                   | Value                                        |
+---------------------------------+----------------------------------------------+
| log_bin                         | ON                                           |
| log_bin_basename                | /mysql/3306/data/master       |
| log_bin_index                   | /mysql/3306/data/master.index |
| log_bin_trust_function_creators | OFF                                          |
| log_bin_use_v1_row_events       | OFF                                          |
| sql_log_bin                     | ON                                           |
+---------------------------------+----------------------------------------------+

binlog文件的读取

MySQL在启动时会读取data目录下的所有以.index后缀的文件(默认值),然后在读取每个index文件中的条目

官方文档

The default location for binary log files and the binary log index file is the data directory. You can use the --log-bin option to specify an alternative location, by adding a leading absolute path name to the base name to specify a different directory. When the server reads an entry from the binary log index file, which tracks the binary log files that have been used, it checks whether the entry contains a relative path. If it does, the relative part of the path is replaced with the absolute path set using the --log-bin option. An absolute path recorded in the binary log index file remains unchanged; in such a case, the index file must be edited manually to enable a new path or paths to be used. The binary log file base name and any specified path are available as the log_bin_basename system variable.

只摘录了一部分,更全面的内容可到官网查看