https://www.jianshu.com/p/e0d95da89fee
本课程,适合具备一定Linux运维或者开发基础的朋友,课程定级中、高级DBA。
只要掌握80%,轻松助力薪资15k-25K。
课程内容均来自与MySQL官网+MySQL源码。
配套精品视频(2021 5月全新录制,版权所有:郭加磊 oldguo。),获取方法私聊。
默认是关闭的. 可以记录MySQL中发生过的所有操作日志.一般用来调试.
general_log = ON
general_log_file = /data/3306/data/db01.log
审计
调试
记录数据库从启动以来,状态\报错\警告.
mysql> show variables like '%error%';
log_error = ./db01.err
log_error_verbosity=3
mysql> set global log_error_verbosity=3;
每天定时巡检.主要关注 [ERROR] ,[WARNING]
以event形式,记录MySQL数据库中变更类的操作日志(DDL DCL DML).
数据恢复.
复制
mysql> show variables like '%bin%';
log_bin=1
log_bin_basename=/data/3306/data/binlog
sync_binlog=1
binlog_format=row/statement/mixed
sync_binlog=1 是双一期中一个1.保证事务提交理解刷新binlog到磁盘.
binlog_format=row/statement/mixed
格式区别:
1. row (RBR) : 记录每个数据行的真实变化. 日志量会比较大.记录足够准确.
update t1 set num=20 where id<10;
2. statement(SBR) : 记录发生的是语句.日志量相对少.记录有可能不准确.
3. mixed 混合模式
binlog_format 只影响DML语句.DDL和DCL都是Statement
mysql> show binary logs;
mysql> show master status ;
mysql> show binlog events in 'binlog.000007';
[root
故障模拟:
mysql> flush logs;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status ;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000008 | 156 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> create database oldboy;
Query OK, 1 row affected (0.01 sec)
mysql> use oldboy;
Database changed
mysql> create table t1 (id int);
Query OK, 0 rows affected (0.10 sec)
mysql> insert into t1 values(1);
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values(2);
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values(3);
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK