mysql 二進位logs

來源:互聯網
上載者:User

最近頻繁接到資料庫伺服器磁碟空間不足的警示,實際上資料庫檔案本身不大,主要是半年多累積的binary logs大,尤其是有主從配置的DB。查看了很多資料,總結了一下常用的專門針對binary logs的mysql命令:

1. Binary logs 位置:

1)查看/etc/my.cnf (Windows下為my.ini), 例如:

log_bin=/var/mydb/bin-log

如果該設定沒帶路徑,就放在datadir=/var/lib/mysql 下

2) 到資料庫查看是否開啟binary log 功能:

mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin            | ON    |
+---------------+-------+
1 row in set (0.00 sec)

mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin             | OFF   |
+---------------+-------+
1 row in set (0.01 sec)

如果是OFF就沒有以下工作了:)

2. 查看當前工作的logfile名及大小: show binary logs /show master logs;

mysql> show binary logs;
+-----------------+-----------+
| Log_name           | File_size |
+-----------------+-----------+
| bin-log.000011 |    148329 |
+-----------------+-----------+

mysql> show master logs;
+-----------------+-----------+
| Log_name           | File_size |
+-----------------+-----------+
| bin-log.000011 |    148329 |
+-----------------+-----------+

mysql> show binary logs;
ERROR 1381 (HY000): You are not using binary logging ###沒有開啟binary logs

3. 清除所有binary logs;

1)

mysql> show master logs;
+-----------------+-----------+
| Log_name        | File_size |
+-----------------+-----------+
| log-bin.000001 |    259548 |
| log-bin.000002 |     37200 |
| log-bin.000003 |     74219 |
+-----------------+-----------+
3 rows in set (0.00 sec)

mysql> reset master; (在slave上,用reset slave,之前應stop slave,之後再start slave)
Query OK, 0 rows affected (0.00 sec)

mysql> show master logs;
+-----------------+-----------+
| Log_name        | File_size |
+-----------------+-----------+
| log-bin.000001 |        98 |
+-----------------+-----------+
1 row in set (0.00 sec)

4. 清除指定部分logs:

mysql>purge binary logs to 'log-bin.000012';

將log-bin.000012之前的binary logs清掉;

mysql>purge binary logs before '2011-05-28 12:05:38';

將指定時間之前的binary logs清掉;

5.查看當前binary log的情況:

mysql>show master status;

6. 查看binary logs的內容:

mysql>show binlog events;

命令列下:

#mysqlbinlog /var/log/mysql/log-bin.000140; 或者

#mysqlbinlog --start-datetime='2011-07-01 00:00:00' --stop-datetime='2010-07-15 00:00:00' /var/log/mysql/log-bin.000020 > ./tmp.log

7. 在my.cnf/my.ini中設定binary logs復原天數:

expire_logs_days = 7

相關文章

聯繫我們

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