ib_logfile和binary log file的区别

1.两者的区别:

 

The ib_logfile's hold statements affecting innodb tables only. If a crash occurs they are automatically used to complete any innodb transactions that didn't complete before the crash.


The bin logs record all statements that update data, regardless of engine. They are useful when you have to restore a backup and then roll forward to particular point in time and also to review what statements have been run.

iblogfile is temporary, only live till the data is updated into the tablespace, after which the space is reused.
binary log is more or a permanent and you have to purge the old logs yourself when it is not requried anymore.

 


 

2.如何查看两者的内容


使用下面的命令查看binlog里的内容
$ mysqlbinlog mysql-bin.<logfile-number>

注意:mysqlbinlog位于mysql的bin目录下,如果你的my.cnf的配置里面有:

[client]
default-character-set=utf8

执行时报unknown variable 'default-character-set=utf8'错误,这时可以改成:

[client]
loose-character-set = utf8

使用宽泛的设置,参见:http://blog.youkuaiyun.com/fafa211/article/details/2361066



使用下面的命令查看ib_logfile里的内容
$ strings ib_logfile<file-no.>

 

MySQL 的 Redo Log(日志文件)主要用于事务恢复数据一致性,它记录了对数据库所做的所有修改操作,以便在系统崩溃后能够重做这些操作,保持数据库的一致性。当你需要启用 Redo Log 来支持事务时,通常涉及以下几个步骤: 1. **开启二进制日志(Binary Logging)**:MySQL 的 Redo Log 实际上就是二进制日志的一种形式,它是通过 `binlog_format` 参数控制开启。你可以设置为 `ROW` 或 `STATEMENT` 格式,以便记录完整的事务内容。 ```sql SET GLOBAL binlog_format = 'ROW'; // 或者 'STATEMENT' ``` 如果你的服务器配置已经默认开启了二进制日志,那么这个步骤就不必要,因为默认情况下 MySQL 就会生成 Redo Log。 2. **启用事务**:当开始一个事务时,MySQL 会自动将事务相关的更改写入到 redo log 中,直到事务提交(COMMIT)或者回滚(ROLLBACK)。 ```sql START TRANSACTION; ... (执行SQL语句) COMMIT; // 或 ROLLBACK IF NEEDED; ``` 3. **设置适当的redo log配置**:确认你的 `innodb_log_files_in_group` `ib_log_file_size` 等参数足够大,以存储大量的事务日志,并定期 ` Rotate logs` 或者 `Flush Logs` 来清理旧的日志,避免磁盘空间不足。 4. **检查错误处理同步**:确保你的 MySQL 配置正确处理 I/O 错误,比如 `innodb_flush_log_at_trx_commit` 设置为 `1` 表示每次提交都同步到磁盘,降低丢失未提交事务的风险。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值