国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL 自動清理binlog日志的方法

2024-07-24 12:53:30
字體:
來源:轉載
供稿:網友

說明:

開啟MySQL binlog日志的服務器,如果不設置自動清理日志,默認binlog日志一直保留著,時間一長,服務器磁盤空間被binlog日志占滿,導致MySQL數據庫出錯。

使用下面方法可以安全清理binlog日志

一、沒有主從同步的情況下清理日志

mysql -uroot -p123456 -e 'PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ),INTERVAL 5 DAY)';

#mysql 定時清理5天前的binlog

mysql -u root -p  #進入mysql 控制臺

reset master;  #重置binlog

二、MySQL主從同步下安全清理binlog日志

1、mysql  -u root -p   #進入從服務器mysql控制臺
show slave status/G;   #檢查從服務器正在讀取哪個日志,有多個從服務器,選擇時間最早的一個做為目標日志。
2、進入主服務器mysql控制臺

show master log;   #獲得主服務器上的一系列日志
PURGE MASTER LOGS TO 'binlog.000058';   #刪除binlog.000005之前的,不包括binlog.000058
PURGE MASTER LOGS BEFORE '2016-06-22 13:00:00';  #清除2016-06-22 13:00:00前binlog日志
PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 3 DAY);  #清除3天前binlog日志

三、設置自動清理MySQL binlog日志

vi  /etc/my.cnf  #編輯配置

expire_logs_days = 15 #自動刪除15天前的日志。默認值為0,表示從不刪除。log-bin=mysql-bin #注釋掉之后,會關閉binlog日志binlog_format=mixed #注釋掉之后,會關閉binlog日志

:wq!  #保存退出

擴展閱讀:

mysql> help purge;

Name: 'PURGE BINARY LOGS'

Description:

Syntax:

PURGE { BINARY | MASTER } LOGS

{ TO 'log_name' | BEFORE datetime_expr }

The binary log is a set of files that contain information about data

modifications made by the MySQL server. The log consists of a set of

binary log files, plus an index file (see

http://dev.mysql.com/doc/refman/5.5/en/binary-log.html).

The PURGE BINARY LOGS statement deletes all the binary log files listed

in the log index file prior to the specified log file name or date.

BINARY and MASTER are synonyms. Deleted log files also are removed from

the list recorded in the index file, so that the given log file becomes

the first in the list.

This statement has no effect if the server was not started with the

--log-bin option to enable binary logging.

URL: http://dev.mysql.com/doc/refman/5.5/en/purge-binary-logs.html

Examples:

PURGE BINARY LOGS TO 'mysql-bin.010';

PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';

下面是其它網友給出的方法,大家可以參考一下

MYSQL主從復制(replication)采用 RBR 模式后,binlog的格式為"ROW",能解決很多原先出現的主鍵重復問題。
在一個繁忙的master db server上,binlog日志文件增長速度很快,如果不定時清除,硬盤空間很快就會被充滿。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 修文县| 光山县| 江阴市| 偏关县| 新蔡县| 抚顺县| 阿尔山市| 晋州市| 五大连池市| 沿河| 山阳县| 宁化县| 九寨沟县| 瓦房店市| 大余县| 安丘市| 大足县| 南丹县| 资兴市| 武陟县| 南澳县| 镇沅| 九江市| 巍山| 屏山县| 五大连池市| 大化| 冀州市| 襄汾县| 吉林省| 微山县| 岐山县| 凉山| 城口县| 南昌市| 辛集市| 遂宁市| 凤凰县| 犍为县| 米林县| 工布江达县|