在centos7下设置mysql的binlog
修改/etc/my.cnf文件 增加如下配置
# 必须设置server-id 每台机器的不要重复 在 MySQL 5.7.3 及以后版本,如果没有设置server-id, 那么设置binlog后无法开启MySQL服务.
server-id=1001
#binlog的文件路径到文件名
log-bin=
#系统变量binlog_format 指定二进制日志的类型。分别有STATEMENT、ROW、MIXED三种值。MySQL #5.7.6之前默认为STATEMENT模式。MySQL 5.7.7之后默认为ROW模式。这个参数主要影响主从复#制。
#复制的模式有下面几种:基于SQL语句的复制(statement-based replication, SBR),基于行的复制(row-based replication, RBR),混合模式复制(mixed-based replication, MBR)。
binlog_format=Row
重启mysql systemctl restart mysqld.service
进入mysql后 使用 show variables like 'log_%'; 查看binlog配置

使用 show master logs; 查看binlog日志
到这里binlog就配置好了
在配置中遇到的问题。
1 binlog目录的权限问题
需要指定binlog所在目录拥有者是mysql
chown mysql.mysql /var/lib/mysql/binlog/
设置执行权限
chmod -R 755 /var/lib/mysql/binlog/
2 centos7 在home文件夹下设置binlog不可用
开始我设置的binlog的目录是在home文件夹下面,并且给它分组设置的权限 但启动一直报错。
2019-10-23T07:36:27.583316Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-23T07:36:27.584413Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.28-log) starting as process 9866 ...
mysqld: File '/home/logs/binlog.index' not found (Errcode: 13 - Permission denied)
2019-10-23T07:36:27.586155Z 0 [ERROR] Aborting
查了很多资料无果后,把binlog路径设置到mysql的安装目录下发现可以设置。
不能设置在home路径下的原因没有查明,等以后再查询。
关闭selinux 如下:
临时关闭:
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
永久关闭:
[root@localhost ~]# vim /etc/sysconfig
SELINUX=enforcing 改为 SELINUX=disabled
重启服务reboot
关闭selinux后就可以设置binlog在home下了

但关闭selinux后可能安全,为了安全可以考虑配置到其他目录下。