12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MySQL の バイナリログ の消し方

Last updated at Posted at 2020-01-25

MySQL の バイナリログ

/etc/my.cnf に log-bin = log-name を設定するとバイナリログを出力できますが、
デフォルトの設定だと MySQL を再起動したタイミングやバイナリログの最大容量(デフォルトでは最大の1GB)に達した時点でローテートされログが増え続けてしまいます。

現在の設定

/etc/my.cnf
[mysqld]
log-bin = log-name

log の状況

# ls /var/lib/mysql/
-rw-rw----  1 mysql mysql 10491971 12月 19 12:37 log-name.000001
-rw-rw----  1 mysql mysql      143 12月 19 13:04 log-name.000002
-rw-rw----  1 mysql mysql  1718471  1月 21 09:07 log-name.000003
-rw-rw----  1 mysql mysql       60 12月 19 13:05 log-name.index

show master logs の状況

mysql> show master logs;
+-------------------+-----------+
| Log_name          | File_size |
+-------------------+-----------+
| ujm-server.000001 |  10491971 |
| ujm-server.000002 |       143 |
| ujm-server.000003 |   1718471 |
+-------------------+-----------+

手動でのバイナリログを削除

SQL を実行

mysql> purge master logs to 'ujm-server.000001';
Query OK, 0 rows affected (0.01 sec)

結果を表示

mysql> show master logs;
+-------------------+-----------+
| Log_name          | File_size |
+-------------------+-----------+
| ujm-server.000002 |       143 |
| ujm-server.000003 |   1718471 |
+-------------------+-----------+
2 rows in set (0.00 sec)

自動でバイナリログを削除

expire_logs_days を設定します。

現在の設定

mysql> show variables like 'expire_logs_days';

SQL を実行

mysql> SET GLOBAL expire_logs_days = 10;

今回は10日にしました。

変更後の設定

mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 10    |
+------------------+-------+
1 row in set (0.00 sec)
12
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?