centos 7 mysql 开启binlog

一、前言

本文章用到的mysql 为5.7版本。

按照https://blog.csdn.net/king_kgh/article/details/74800513中的步骤操作,结果启动失败。

配置文件在 /etc/mysqld

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin=ON
log_bin_basename=/var/lib/mysql/mysql-bin
log_bin_index=/var/lib/mysql/mysql-bin.index
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

启动失败后,发现日志文件/var/log/mysqld.log竟然是空的,什么都没有。

二、解决

启动失败提示如下:

centos 7 mysql 开启binlog

于是照着提示执行了:

centos 7 mysql 开启binlog

这个并没看出任何的错误线索。

接着执行:

centos 7 mysql 开启binlog

这里就清楚了,原来是没有设置server-id。

那就指定一下吧。

log_bin=ON
log_bin_basename=/var/lib/mysql/mysql-bin
log_bin_index=/var/lib/mysql/mysql-bin.index
server-id=123454

再次重启。

结果又报错了,查看/var/log/mysqld.log,发现提示如下:

2019-02-26T06:50:46.581796Z 0 [ERROR] unknown variable 'log_bin_basename=/var/lib/mysql/mysql-bin'
2019-02-26T06:50:46.581811Z 0 [ERROR] Aborting

好吧。。。这网上的教程坑多啊。

后边直接看了官网:

16.1.2.1 Setting the Replication Master Configuration

To configure a master to use binary log file position based replication, you must enable binary logging and establish a unique server ID. If this has not already been done, a server restart is required.

Binary logging must be enabled on the master because the binary log is the basis for replicating changes from the master to its slaves. If binary logging is not enabled on the master using the log-bin option, replication is not possible.

Each server within a replication group must be configured with a unique server ID. This ID is used to identify individual servers within the group, and must be a positive integer between 1 and (232)−1. How you organize and select the numbers is your choice.

To configure the binary log and server ID options, shut down the MySQL server and edit the my.cnf or my.ini file. Within the [mysqld] section of the configuration file, add the log-bin and server-id options. If these options already exist, but are commented out, uncomment the options and alter them according to your needs. For example, to enable binary logging using a log file name prefix of mysql-bin, and configure a server ID of 1, use these lines:

[mysqld]
log-bin=mysql-bin
server-id=1

After making the changes, restart the server.

于是,把原来的配置改成和官网一样:

[mysqld]

log-bin=mysql-bin

server-id=1

三、查看binlog文件

1、mysql> show variables like '%log_bin%';

centos 7 mysql 开启binlog

2、查看目录

centos 7 mysql 开启binlog

3、show master status;

查看当前正在写入的binlog文件

centos 7 mysql 开启binlog

4、mysql> show binlog events;

centos 7 mysql 开启binlog

5、mysql> show binlog events in 'mysql-bin.000001';

查看指定的文件

内容同上。

6、mysql> show binary logs;

显示文件列表。

centos 7 mysql 开启binlog

7、也可以用mysqlbinlog查看

https://www.cnblogs.com/snifferhu/p/5280489.html

8、查看binlog相关参数

show variables like "%binlog%";

标红的都是我目前知道的,比较重要的。

centos 7 mysql 开启binlog

在innodb存储引擎那本书里,重点说了下面的几个参数(也很值得了解下):

centos 7 mysql 开启binlog

上一篇:python之面向对象进阶


下一篇:get/close not same thread Druid 连接池一个设置