centos7 中的mysql5.7 开启binlog 日志

1、查看mysql 是否有开启binlog日志

show VARIABLES LIKE 'log_%';

  

log_bin	ON    //这项如果是OFF这是关闭,还没有开启     
log_bin_basename	/var/lib/mysql/mysql_bin
log_bin_index	/var/lib/mysql/mysql_bin.index
log_bin_trust_function_creators	OFF
log_bin_use_v1_row_events	OFF
log_builtin_as_identified_by_password	OFF
log_error	/var/log/mysqld.log
log_error_verbosity	3
log_output	FILE
log_queries_not_using_indexes	OFF

  2、开启

Linux下的mysql配置文件为my.cnf ,windows下为my.ini

配置文件目录 /etc/my.cnf

[root@localhost ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[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
#
# 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
secure_file_priv=
character-set-server=utf8
collation-server=utf8_general_ci
max_connections=1000
table_open_cache=6000
thread_cache_size=50
open_files_limit=8000
event_scheduler=ON

group_concat_max_len=999999999999
# 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

开启的话需要添加几行配置如下:

# changes to the binary log between backups.
log_bin=mysql_bin
binlog-format=Row
server-id=1
#

  我的完整配置

[root@localhost ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[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-format=Row
server-id=1
#
# 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
secure_file_priv=
character-set-server=utf8
collation-server=utf8_general_ci
max_connections=1000
table_open_cache=6000
thread_cache_size=50
open_files_limit=8000
event_scheduler=ON

group_concat_max_len=999999999999
# 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

  3.重启mysql

[root@localhost ~]# service mysqld restart

  4.查看是否生成了文件,文件目录默认是在 /var/lib/mysql 下以mysql-bin.00000X等做名称,而mysqld-bin.index则是记录了所有的log的文件名称

      5.使用时则使用下面的命令等来追踪database的操作

 mysqlbinlog /var/lib/mysql|grep "*****"

  

posted @ 2022-07-23 16:03  慕容天白  阅读(933)  评论(0编辑  收藏  举报