- 查看系统版本
[root@Lime-CentOS ~]# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core)
- 查看MySQL版本
root@Lime-CentOS ~]# mysql --help | grep Distrib mysql Ver 14.14 Distrib 5.7.32, for Linux (x86_64) using EditLine wrapper
- 检查是否开启binlog
mysql> show variables like '%log_bin%'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | log_bin | OFF | | log_bin_basename | | | log_bin_index | | | log_bin_trust_function_creators | OFF | | log_bin_use_v1_row_events | OFF | | sql_log_bin | ON | +---------------------------------+-------+ 6 rows in set (0.00 sec)
- log-bin开启binlog
[root@Lime-CentOS ~]# vim /etc/my.cnf [mysqld] # binlog config # 开启 Binlog 并写明存放日志的位置;默认使用的设置是“log-bin=mysql-bin”,这样日志是存放在默认的位置上的,一般是放在data目录中。 log-bin=mysql-bin # 指定一个集群内的 MySQL 服务器 ID,如果做数据库集群那么必须全局唯一,一般来说不推荐 指定 server-id 等于 1。 server-id=1 # 设置Bin-log日志模式。 binlog_format=ROW
- 重启MySQL服务
root@Lime-CentOS ~]# sudo systemctl restart mysqld
- 查看有哪些binlog
mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 177 | | mysql-bin.000002 | 154 | +------------------+-----------+ 2 rows in set (0.00 sec) mysql> show master logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 177 | | mysql-bin.000002 | 154 | +------------------+-----------+ 2 rows in set (0.00 sec)
- 查看第一个binlog的内容
mysql> show binlog events; +------------------+-----+----------------+-----------+-------------+---------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-----+----------------+-----------+-------------+---------------------------------------+ | mysql-bin.000001 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.32-log, Binlog ver: 4 | | mysql-bin.000001 | 123 | Previous_gtids | 1 | 154 | | | mysql-bin.000001 | 154 | Stop | 1 | 177 | | +------------------+-----+----------------+-----------+-------------+---------------------------------------+ 3 rows in set (0.00 sec)
- 指定查看具体的binlog日志的内容
mysql> show binlog events in 'mysql-bin.000002'; +------------------+-----+----------------+-----------+-------------+---------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-----+----------------+-----------+-------------+---------------------------------------+ | mysql-bin.000002 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.32-log, Binlog ver: 4 | | mysql-bin.000002 | 123 | Previous_gtids | 1 | 154 | | +------------------+-----+----------------+-----------+-------------+---------------------------------------+ 2 rows in set (0.00 sec)
- 查看当前正在写入的binlog日志文件
mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000002 | 154 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
- 重新开始一个日志文件
mysql> flush logs; Query OK, 0 rows affected (0.01 sec)
- 在row模式下..开启该参数,将把sql语句打印到binlog日志里面.默认是0(off);
mysql> select @@binlog_rows_query_log_events; +--------------------------------+ | @@binlog_rows_query_log_events | +--------------------------------+ | 0 | +--------------------------------+ 1 row in set (0.00 sec) mysql> set binlog_rows_query_log_events = 1; Query OK, 0 rows affected (0.00 sec) mysql> select @@binlog_rows_query_log_events; +--------------------------------+ | @@binlog_rows_query_log_events | +--------------------------------+ | 1 | +--------------------------------+ 1 row in set (0.00 sec)
- binlog_row_image
-- 默认为full. -- 在binlog为row格式下, -- full将记录update前后所有字段的值, -- minimal时,只记录更改字段的值和where字段的值, -- noblob时,记录除了blob和text的所有字段的值,如果update的blob或text字段,也只记录该字段更改后的值,更改前的不记录; select @@binlog_row_image; set binlog_row_image='minimal';
- 查看binlog_cache_use、binlog_cache_disk_use的状态
-- 当使用事务的表存储引擎时,所有未提交(uncommitted)的二进制日志会被记录到一个缓存中去, -- 等该事物提交(committed)时直接将缓冲中的二进制日志写入二进制日志文件, -- 而该缓冲的大小由binlog_cache_size决定,默认大小为32K。此外, -- binlog_cache_size是基于会话(session)的,也就是说,当一个线程开始一个事务时, -- MySQL会自动分配一个大小为binlog_cache_size的缓存,因此该值的设置需要相当小心, -- 不能设置过大。当一个事务的记录大于设定的binlog_cache_size时, -- MySQL会把缓冲中的日志写入一个临时文件中,因此该值又不能设得太小。 -- 通过SHOW GLOBAL STATUS 命令查看binlog_cache_use、binlog_cache_disk_use的状态, -- 可以判断当前binlog_cache_size的设置是否合适。 -- binlog_cache_use记录了使用缓冲写二进制日志的次数, -- binlog_cache_disk_use记录了使用临时文件写二进制日志的次数。 mysql> SHOW GLOBAL STATUS\G *************************** 3. row *************************** Variable_name: Binlog_cache_disk_use Value: 0 *************************** 4. row *************************** Variable_name: Binlog_cache_use Value: 0
- 删除日志索引文件中记录的所有binlog文件,创建一个新的日志文件,起始值从000001开始
mysql> reset master; Query OK, 0 rows affected (0.01 sec)
- sync_binlog = 1
- innodb_support_xa = 1
- binlog-do-db
- binlog-ignore-db
- log-slave-update
- mysqlbinlog
- 根据备份的方法
- 热备份
- MVCC
- ibbackup
- xtrabackup
- mysqldump --single-transaction
- 冷备份
- frm文件
- 共享表空间
- 独立表空间文件
- 重做日志文件
- 温备份
- 热备份
- 按照备份后文件的内容
- 逻辑备份
- 裸文件备份
- 按照备份数据库的内容
- 完全备份
- 增量备份
- 日志备份
- REDO
- UNDO
- 啦啦啦
- 啦啦啦
CentOS 7.4 MySQL 5.7 binlog
最新推荐文章于 2024-06-03 15:06:42 发布