MySQL Binlog的介绍
binlog基本定义:二进制日志,也成为二进制日志,记录对数据发生或潜在发生更改的SQL语句,并以二进制的形式保存在磁盘中;作用:
binlog基本定义:二进制日志,也成为二进制日志,记录对数据发生或潜在发生更改的SQL语句,并以二进制的形式保存在磁盘中;
作用:MySQL的作用类似于Oracle的归档日志,可以用来查看数据库的变更历史(具体的时间点所有的SQL操作)、数据库增量备份和恢复(增量备份和基于时间点的恢复)、Mysql的复制(主主数据库的复制、主从数据库的复制)
二进制日志的信息:
文件位置:默认存放位置为数据库文件所在目录下
文件的命名方式: 名称为hostname-bin.xxxxx (重启mysql一次将会自动生成一个新的binlog)
状态的查看:mysql> show variables like '%log_bin%';
mysql> show variables like '%log_bin%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin | ON | //表示当前已开启二进制日志//
| log_bin_trust_function_creators | OFF |
| sql_log_bin | ON |
+---------------------------------+-------+
3 rows in set (0.00 sec)
二进制日志的管理:
1、开启二进制日志配置
方法一、修改my.cnf参数文件,该方法需要重启
log-bin = mysql-bin #打开日志(主机需要打开),这个mysql-bin也可以自定义,这里也可以加上路径,如:/home/www/mysql_bin_log/mysql-bin
关闭二进制日志的方法:log-bin = mysql-bin注释掉即可
方法二、不重启修改二进制日志配置,该方法mysql的版本需要5.6以上
SET @@global.log_bin=1|0 (1为开启,0为关闭)
SET @@global.binlog_size=37268(单位bytes)
3、暂停二进制日志
SET sql_log_bin={0|1}
4、修改二进制日志的大小
修改my.cnf参数文件中的max_binlog_size的值;
说明:如果你的二进制文件的大小超过了max_binlog_size,它就是自动创建新的二进制文件。当然如果恰好在日志文件到达它的最大尺寸时写入了大的事务,,那么日志文件还是会超过max_binlog_size的大小
5、进行二进制日志的切换,默认情况下当二进制日志写满了或者数据库重启了才会进行切换,但是也可以手工的进行切换的动作
mysql> flush logs;
6、其他参数:
binlog-cache-size=100m 设置二进制日志缓存大小
sync-binlog=N(每个N秒将缓存中的二进制日志记录写回硬盘,默认值为0。不过,你经常会陷入group commit函数与I/O之间二选一的矛盾。如果在replication环境中,由于考虑到耐久性与一致性,则需要设置1。同时,还需要设置innodb_flush_log_at_trx_commit=1以及innodb-support-xa=1默认开启;)
二进制日志的写入过程
查看二进制日志的内容:
binlog不能直接用文本的方式打开,mysql提供了相应的查看工具:mysqlbinlog,直接查看单个二进制日志文件:mysqlbinlog filename
例如: mysqlbinlog /data/mysql/mysql-bin.000001
当然也可以通过二进制日志完成数据库的恢复,具体的使用将在数据库的备份还原中介绍。
删除二进制日志
二进制日志会不断的增长,并产生多个文件。因此,需要制定备份计划和管理策略.无用的二进制日志要记得及时删除。
删除慢查询日志有三种方法:
1、操作系统命令直接删除
2、reset master
3、PURGE BINARY LOGS BEFORE '2014-07-09 12:40:26′;
总结:二进制日志用途广泛也很重要,大多少情况下会开启,对于业务操作频繁的数据库需要制定相应的备份策略和删除策略;
MySQL数据恢复--binlog
MySQL中binlog日记清理
如何安全删除MySQL下的binlog日志
MySQL--binlog日志恢复数据
MySQL删除binlog日志及日志恢复数据的方法
MySQL binlog三种格式介绍及分析
MySQL 利用binlog增量备份+还原实例
MySQL删除binlog日志及日志恢复数据
本文永久更新链接地址:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PrimeFactor−Innumbertheory,theprimefactorsofapositiveintegeraretheprimenumbersthatdividethatintegerexactly.Theprocessoffindingthesenumbersiscalledintegerfactorization,orprimefactorization.Example−Primefactorsof288are:288=2x2x2x2x2

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.

Top 10 digital currency trading platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini, these exchanges have their own characteristics, and users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

This article recommends ten digital currency trading apps: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Poloniex. When choosing a platform, you need to consider factors such as security, liquidity, transaction fees, currency selection, user interface, customer service support and regulatory compliance, and carefully evaluate risks and never blindly follow the trend.

This article provides Android and Apple mobile APP download methods for mainstream digital currency trading platforms such as Binance, OKX, Gate.io, Huobi Global, Coinbase, KuCoin, Kraken and Bitfinex. Whether it is an Android user or an Apple user, you can easily find the official APP download link for the corresponding platform and complete the installation according to the steps. The article provides detailed guidance on searching and downloading on their respective official websites or app stores, and provides instructions on the special steps for installing APK files on Android, so that users can download and use them quickly and easily.

Reliable digital currency platforms include: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini. These exchanges have their own characteristics. Users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

The rankings of the top ten virtual currency trading platforms are: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Gemini. The ranking is based on comprehensive considerations such as platform liquidity, currency selection, security, user experience, handling fees and compliance, but is for reference only. Investment should be cautious and at your own risk.
