mysql binlog 权限_MySQL如何开启binlog?binlog三种模式的分析

本文介绍了如何检查和开启MySQL的binlog日志,详细解析了my.cnf配置文件中涉及binlog的相关参数,包括日志格式、路径、清理时间和大小等。同时,文章深入探讨了binlog的三种模式(STATEMENT、ROW、MIXED)的优缺点,并通过实例展示了不同模式下的binlog内容差异。最后,列举了一些常用的binlog管理命令。
摘要由CSDN通过智能技术生成

前提,创建表t,并插入数据,语句如下:

CREATE TABLE `t` (

`id` int(11) NOT NULL,

`a` int(11) DEFAULT NULL,

`t_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

PRIMARY KEY (`id`),

KEY `a` (`a`),

KEY `t_modified`(`t_modified`)

) ENGINE=InnoDB;

insert into t values(1,1,'2018-11-13');

insert into t values(2,2,'2018-11-12');

insert into t values(3,3,'2018-11-11');

insert into t values(4,4,'2018-11-10');

insert into t values(5,5,'2018-11-09');

判断MySQL是否已经开启binlog?

登录mysql,执行:SHOW VARIABLES LIKE 'log_bin';

OFF:关闭

ON:开启

如何开启binlog日志?

找到my.cnf :

select @@basedir;

如果还是找不到文件的位置,可以执行下面命令,可以得到mysql的配置文件的默认加载顺序

mysql --help | grep 'Default options' -A 1

执行结果:

Default options are read from the following files in the given order:

/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

可以看到mysql优先加载/etc/my.cnf中的配置。

所以需要在/etc/my.cnf中mysqld节添加开启binlog的配置,如下有两种方式:

#第一种方式:

#开启binlog日志

log_bin=ON

#binlog日志的基本文件名

log_bin_basename=/var/lib/mysql/mysql-bin

#binlog文件的索引文件,管理所有binlog文件

log_bin_index=/var/lib/mysql/mysql-bin.index

#配置serverid

server-id=1

#第二种方式:

#此一行等同于上面log_bin三行

log-bin=/var/lib/mysql/mysql-bin

#配置serverid

server-id=1

修改完配置后,重启mysql。执行SHOW VARIABLES LIKE 'log_bin'; Value 值为 ON即可。

binlog的配置简介

MySQL配置文件my.cnf文件中的mysqld节的配置:

[mysqld]

#设置日志三种格式:STATEMENT、ROW、MIXED 。

binlog_format = mixed

#设置日志路径,注意路经需要mysql用户有权限写

log-bin = /data/mysql/logs/mysql-bin.log

#设置binlog清理时间

expire_logs_days = 7

#binlog每个日志文件大小

max_binlog_size = 100m

#binlog缓存大小

binlog_cache_size = 4m<

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值