mysql 刪除記錄檔命令詳解

來源:互聯網
上載者:User

如果沒有主從複製,可以通過reset master的方式,重設資料庫日誌,清除之前的記錄檔:

 代碼如下 複製代碼

mysql> reset master;


還有一各就是在my.cnf裡配置。

 代碼如下 複製代碼

expire_logs_days = 3

二進位日誌自動刪除的天數。這裡設定了自動清除3天前的logs。

預設值為0,表示“沒有自動刪除”。


 代碼如下 複製代碼

# 按檔案:刪除mysql-bin.000354之前的日誌,不包含mysql-bin.000354

MYSQL>purge binary logs to 'mysql-bin.000354';

Query OK, 0 rows affected (0.16 sec)

# 按時間:刪除2011-11-10 00:00:00 之前的日誌

MYSQL>purge binary logs before '2011-11-10 00:00:00';

# 按時間:請理三天之前的日誌

MYSQL> purge master logs before date_sub(now(), interval 3 day);

自動清理日誌 :

# 修改my.cnf檔案配置bin-log到期時間

[mysqld]

expire-logs-days=7

max-binlog-size=268435456


如果你是主從mysql記錄檔請參考下面方法

 代碼如下 複製代碼

//刪除日誌之前,先檢查主從伺服器當前使用的記錄檔,


//首先登入 要刪除日誌的伺服器的 mysql 終端
#mysql -u root -pxxxxx


//檢查複製主伺服器狀態
Mysql>show master status


+------------------+-----------+--------------+----------------------------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB                       |
+------------------+-----------+--------------+----------------------------------------+
| mysql-bin.000097 | 541677824 | www      | test,mysql,information_schema |
+------------------+-----------+--------------+----------------------------------------+


//複製主伺服器當前正在使用的記錄檔是:mysql-bin.000097


//檢查複製從伺服器狀態
Mysql>show slave statusG

 

//複製從伺服器當前正在使用的複製主伺服器記錄檔是:mysql-bin.000103

 


//當前正在使用的記錄檔是000097,我需要做的是刪除00095號之前的所有日誌(預留出最近幾天的日誌)
Mysql>purge master logs to ‘mysql-bin.000095;

 


#ll /usr/local/mysql/var/


//從結果中發現,編號000097之前的所有日誌都已經刪除

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.