要开启MySQL的二进制日志(binlog),需按照以下步骤进行操作: 1. 打开MySQL配置文件:首先,找到MySQL的配置文件my.cnf(或my.ini,视操作系统而定)。 2. 找到并修改binlog相关配置:在配置文件中找到以下几个参数,如果没有则手动添加: [mysqld] log-bin=mysql-bin # 开启binlog,设置binlog文件名 binlog-format=ROW # 设置binlog格式,可选值为STATEMENT、ROW、MIXED server-id=1 # 设置MySQL实例的唯一ID,不同实例要设置不同的ID log-bin=/var/lib/mysql/mysql-bin
systemctl restart mysql
[root@VM-4-11-centos mysql]# mysqlbinlog -v mysql-bin.000003
[mysqld]
binlog_format=STATEMENT
更改binlog输出格式 ,更改完 日志输出 的是SQL语句
update test set name='xiaoming' where name='xiaobao'
/*
#240131 13:48:31 server id 1 end_log_pos 337 CRC32 0xe26ec377 Query thread_id=2 exec_time=0 error_code=0
use `db_test`/*!*/;
SET TIMESTAMP=1706680111/*!*/;
update test set name='xiaoming' where name='xiaobao'
/*!*/;
# at 337
#240131 13:48:31 server id 1 end_log_pos 423 CRC32 0x6b1a0574 Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1706680111/*!*/;
COMMIT
/*!*/;
# at 423
#240131 13:52:31 server id 1 end_log_pos 543 CRC32 0x5df65a64 Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1706680351/*!*/;
create table b(id int ,name varchar(10))
/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
*/
查询日志 ,增删改查 都会记录
查看日志 /var/lib/mysql
[root@VM-4-11-centos mysql]# tail -f mysql_query.log
标签:binlog,log,MYSQL,mysql,日志,id,name From: https://www.cnblogs.com/JIKes/p/17999507