如何开启MySQL 5.7.12 的二进制日志

时间:2021-10-28 10:16:39

1. 打开/etc下的my.cnf文件

如何开启MySQL 5.7.12 的二进制日志

2. 编辑它,添加内容:

log_bin=binary-log   #二进制日志的文件名
server_id=1  #必须指定server_id,这是MySQL 5.7.3以后的要求
binlog-do-db=yrld   #备份的数据库名,可以是多个
binlog-do-db=website
binlog-do-db=yrldgold

如何开启MySQL 5.7.12 的二进制日志 
完整内容:
--------------------------------------------------------------------------------------

# For advice on how to change settings please see
 
[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=mysql-bin
# binlog-do-db=yrld
#
# 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
#忽略大小写
lower_case_table_names=1
#最大连接数
max_connections=1000
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
 
 
# 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
 
[client]
 
default-character-set=utf8mb4
 
[mysqld]
#支持墨迹表情
character-set-server=utf8mb4
character-set-client-handshake = FALSE
collation-server = utf8mb4_unicode_ci
#设置二进制日志
log_bin=binary-log
server_id=1
binlog-do-db=yrld
binlog-do-db=website
binlog-do-db=yrldgold
 
[mysql]
 
default-character-set=utf8mb4

--------------------------------------------------------------------------------------
关于server_id 的说明:
参见官网:
http://dev.mysql.com/doc/refman/5.7/en/replication-options-binary-log.html#sysvar_log_bin
 
如何开启MySQL 5.7.12 的二进制日志

3. 重启 MySQL

#启动命令
service  mysqld  start
#重启命令
service  mysqld  restart
#停止命令
service  mysqld  stop
#查询状态
service  mysqld  status

查看日志文件:
如何开启MySQL 5.7.12 的二进制日志
日志文件位置在/var/lib/mysql 这也是数据文件的位置,每启动一次mysql就会生成一个日志文件,如binary-log.000001,binary-log.000002 同时还会有binary-log.index文件.