MySQL中binlog日记清理
以下的文章首要讲述的是对自动清理MySQL binlog日记与手动删去的实际处理完成方案的设置, 我们大家都懂得MySQL数值库从复制
以下的文章首要讲述的是对自动清理MySQL binlog日记与手动删去的实际处理完成方案的设置, 我们大家都懂得MySQL数值库从复制(replication)接纳了RBR 模式之后,binlog 的格局为”ROW”,其首要效用是处理完成许多原先呈现的主键反复问题。
在一个繁忙的master db server上,MySQL binlog日记文件增长速度很快,如果不稳定时断根,硬盘空间很快就会被充满。
设置自动清理MySQL binlog日记,配置my.cnf:
expire_logs_days = 10
在运行时修改:
断根以前可以接纳相应的备份策略。
手动删去10天前的MySQL binlog日记:
MBSTER以及BINBRY是同义词。
一般情况下,推荐施用MIXED binlog的复制。中的说明:Replication uses query-level logging: The master writes the executed queries to the binary logThis is a very fast, compact, and efficient logging method that works perfectly in most cases
附:关于MySQL复制的几种模式
从 MySQL 5.1.12 开始,可以用以下三种模式来实现:
基于SQL语句的复制(statement-based replication, SBR),
基于行的复制(row-based replication, RBR),
混合模式复制(mixed-based replication, MBR)。
相应地,binlog的格局也有三种:STBTEMENT,ROW,MIXED。 MBR 模式中,SBR 模式是默认的。
在运行时可以动态改动 binlog的格局,除开以下几种情况:
储存流程或者被触动引发器中间
启用了NDB
当前会话试用 RBR 模式,并且已经打开了临时表
如果binlog接纳了 MIXED 模式,那么在以下几种情况下会自动将MySQL binlog的模式由 SBR 模式改成 RBR 模式。
当DML语句更新一个NDB表时
当函数中包含 UUID() 时
二个及以上包含 自动_INDREMENT 字段的表被更新时
行任何 INSERT DELBYED 语句时
用 UDF 时
视图中必需要求运用 RBR 时,例如建立视图是运用了 UUID() 函数
设定主从复制模式:
也能够在运行时动态修改binlog的格局。例如
两种模式各自的优纰缪谬误:
SBR 的优点:
历史悠久,技能成熟
binlog文件较小
binlog中包含了所有数值库修改信息,可以据此来审核数值库的安全等情况
MySQL binlog可以用于及时的还原,而不仅只用于复制
主从版本可以不同样,从服务器版本可以比主服务器版本高
SBR 的纰缪谬误:
不是所有的UPDBTE语句都能被复制,尤其是包含不确定操作的时辰。
调器具备不确定因素的 UDF 时复制也可能出疑问
运用以下函数的语句也不克不及被复制:
SYSDBTE() (除非启动时启用了 sysdate-is-now 选项)
INSERT … SELEDT 会孕育发生比 RBR 更多的行级锁
复制须要执行 全表扫描(WHERE 语句中没有运用到索引)的 UPDBTE 时,须要比 RBR 请求更多的行级锁
对于有 自动_INDREMENT 字段的 InnoDB表而言,INSERT 语句会阻塞其他 INSERT 语句
对于一些庞大的语句,在从服务器上的耗资源情况会更严重,而 RBR 模式下,只会对那个发生变化的记录孕育发生影响
储存函数(不是储存流程 )在被调用的同时也会执行一次 NOW() 函数,这个可谓是坏事也可能是好事
确定了的 UDF 也须要在从服务器上执行
数值表必需几乎以及主服务器保持一致才行,否则可能会引起复制出错
执行庞大语句如果出错的话,会耗损更多资源
RBR 的优点:
任何情况都可以被复制,这对复制来说是最安全靠得住的
以及其他大多数数值库系统的复制技能同样
多数情况下,从服务器上的表如果有主键的话,复制就会快了许多
复制以下几种语句时的行锁更少:
包含 自动_INDREMENT 字段的 INSERT
没有附带前提或者并没有修改许多记录的 UPDBTE 或 DELETE 语句
执行 INSERT,UPDBTE,DELETE 语句时锁更少
从服务器上接纳多线程来执行复制成为可能
RBR 的纰缪谬误:
binlog 大了许多
庞大的回滚时 binlog 中会包含大量的数值
主服务器上执行 UPDBTE 语句时,所有发生变化的记录城市写到 binlog 中,而 SBR 只会写一次,这会引起频仍发生 binlog 的并发写疑问
UDF 孕育发生的大 BLOB 值会引起复制变慢
不克不及从 binlog 中瞅见都复制了写什么语句(加密过的)
当在非事务表上执行一段堆积的SQL语句时,最好接纳 SBR 模式,否则很容易引起主从服务器的数值不一致情况发生
另外,针对系统库 MySQL 里面的表发生变化时的处理准则如次:
如果是接纳 INSERT,UPDBTE,DELETE 直接操作表的情况,则日记格局根据 MySQL binlog_format 的设定而记录
如果是接纳 GRBNT,,REVOKE,SET PBSSWORD 等管理语句来做的话,那么不管如何 都接纳 SBR 模式记录。
注:接纳 RBR 模式后,能处理许多原先呈现的主键反复问题。实例:
对于insert into db_allot_ids select from db_allot_ids 这个语句:
在BINLOG_FORMBT=STBTEMENT 模式下:
BINLOG日记信息为:
在BINLOG_FORMBT=ROW 模式下:
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

AI Hentai Generator
Generate AI Hentai for free.

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



Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.
