mysql關閉與刪除bin-log日誌詳解

來源:互聯網
上載者:User

關閉bin-log日誌

當開啟bin-log日誌時,會產生很多mysql-bin.0000*類似的檔案,而且可能會佔用很大的硬碟空間。對於自己的測試機器或硬碟比較緊張的vps,而又不需要做master,slave的配置,完全可以關閉日誌功能。

關閉操作很簡單,找到設定檔my.cnf,對於linux,一般預設在/etc目錄下,開啟此檔案,使用井號(#)注釋掉如下兩個設定項目即可。

 代碼如下 複製代碼

log-bin=mysql-bin
binlog_format=mixed

vi /etc/my.cnf 或my.cnf的路徑

把其中的log-bin=mysql-bin修改為#log-bin=mysql-bin

重啟mysql即可生效。


配置修改好後需要重啟mysqld服務才會生效。

可能在重啟時候會收到一個錯誤,“ERROR 1186 (HY000): Binlog closed, cannot RESET MASTER”,解決辦法是先登入到mysql命令列中執行 reset master 即可。reset master的用途就是刪除先前所以的bin-log記錄檔。所以在master、slave配置環境中慎用此命令。

刪除bin-log日誌

1.尋找當前有哪些二進位記錄檔:

 代碼如下 複製代碼
mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |   1357315 |
| mysql-bin.000002 |       117 |
| mysql-bin.000003 |    404002 |
| mysql-bin.000004 |   2050722 |
| mysql-bin.000005 |    139103 |
| mysql-bin.000006 |     46702 |
| mysql-bin.000007 |       117 |
| mysql-bin.000008 |        98 |
| mysql-bin.000009 |       117 |
| mysql-bin.000010 |      1254 |
| mysql-bin.000011 |       117 |
| mysql-bin.000012 |  29394942 |
| mysql-bin.000013 |    422100 |
| mysql-bin.000014 |       117 |
| mysql-bin.000015 |       117 |
| mysql-bin.000016 |        98 |
| mysql-bin.000017 |       117 |
| mysql-bin.000018 |       117 |
| mysql-bin.000019 |    285300 |
| mysql-bin.000020 |    181229 |
| mysql-bin.000021 |        98 |
+------------------+-----------+
21 rows in set (0.03 sec)

2.刪除bin-log(刪除mysql-bin.000018之前的所有二進位記錄檔)

 代碼如下 複製代碼

mysql> purge binary logs to 'mysql-bin.000018';
Query OK, 0 rows affected (0.08 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000018 |       117 |
| mysql-bin.000019 |    285300 |
| mysql-bin.000020 |    181229 |
| mysql-bin.000021 |        98 |
+------------------+-----------+
4 rows in set (0.00 sec)

mysql> show binlog events;
+------------------+-----+-------------+-----------+-------------+---------------------------------------+
| Log_name         | Pos | Event_type  | Server_id | End_log_pos | Info                                  |
+------------------+-----+-------------+-----------+-------------+---------------------------------------+
| mysql-bin.000018 |   4 | Format_desc |         1 |          98 | Server ver: 5.0.45-log, Binlog ver: 4 |
| mysql-bin.000018 |  98 | Stop        |         1 |         117 |                                       |
+------------------+-----+-------------+-----------+-------------+---------------------------------------+
2 rows in set (0.01 sec)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.