MySQL5.5系からデフォルトでレプリケーションが有効になってた。
MySQL5.5系がデフォルトでレプリケーションが有効に。
あー、悲しい
以前、MySQL5.1から5.5にバージョンアップして、放置していたら
知らぬ間にディスク容量がいっぱいに。。
何が起きた!?と思っていて調べてみると
MySQL5.5系がデフォルトでレプリケーションが有効になっているらしい。
http://www.mk-mode.com/wordpress/2012/05/23002009/
知らなかった。。
ということで、自動削除の設定を行い事なきを得ましたが、
最初はMySQLの障害のような動きで、わけわからない状態に陥ったので
行動ログを記録した↓今度何か起きたら参考にしよう。。
追跡編
[mysql-user]# mysql --version mysql Ver 14.14 Distrib 5.5.19, for Linux (x86_64) using EditLine wrapper
なんかMySQLに接続ができない・・障害と判明し調査を行った。
監視対象から外れていたのもあり、一体何が起きてるのか分らない状態からスタート。
MySQLサーバーが停止していたので、ひとまず再起動しようとするもなぜか失敗。
[mysql-user]# /etc/init.d/mysqld restart MySQL server PID file could not be found! [失敗] Starting MySQL.....................................................................................................The server quit without updating PID file (/usr/local/mysql/data/xxxx.n[失敗]id).
よくかわらなかったので、再起動の様子を tail -f /var/log/mysql_error.log
を眺めていると
InnoDB: Unable to lock ./ibdata1, error: 11 InnoDB: Check that you do not already have another mysqld process InnoDB: using the same InnoDB data or log files. InnoDB: Unable to lock ./ibdata1, error: 11 InnoDB: Check that you do not already have another mysqld process InnoDB: using the same InnoDB data or log files. InnoDB: Unable to lock ./ibdata1, error: 11 InnoDB: Check that you do not already have another mysqld process InnoDB: using the same InnoDB data or log files.
プロセスが既に何個か起動している。。
ps -ef | grep mysql
でひとまずmysqlと名前のつくプロセスを確認後、全部killする。
再度
[mysql-user]# /etc/init.d/mysqld restart
でも失敗するため再度tail -f /var/log/mysql_error.log
120621 xx:xx:xx InnoDB: Waiting for the background threads to start 120621 xx:xx:xx InnoDB: 1.1.8 started; log sequence number 16114096282 /usr/local/mysql/bin/mysqld: Error writing file '/var/lib/mysql/slow_query.log' (Errcode: 28) 120621 xx:xx:xx [ERROR] Could not use /var/lib/mysql/slow_query.log for logging (error 28). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it. 120621 xx:xx:xx [Note] Recovering after a crash using mysql-bin 120621 xx:xx:xx [ERROR] Error in Log_event::read_log_event(): 'read error', data_len: 3616, event_type: 2 120621 xx:xx:xx [Note] Starting crash recovery... 120621 xx:xx:xx [Note] Crash recovery finished. /usr/local/mysql/bin/mysqld: Disk is full writing './mysql-bin.~rec~' (Errcode: 28). Waiting for someone to free space... (Expect up to 60 secs delay for server to continue after freeing disk space) /usr/local/mysql/bin/mysqld: Retry in 60 secs. Message reprinted in 600 secs 120621 xx:xx:xx [Note] Event Scheduler: Loaded 0 events 120621 xx:xx:xx [Note] /usr/local/mysql/bin/mysqld: ready for connections. Version: '5.5.19-log' socket: '/tmp/mysql.sock' port: 3306 Source distribution
Disk is full writing といわれているような感じ。。。うわ。これはもしかして。。と
# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda2 18222732 17283948 0 100% / /dev/hda1 101086 23801 72066 25% /boot tmpfs 255264 0 255264 0% /dev/shm
100%じゃん・・・。
最悪だ。。と思ってディスク容量をチェックしていく
du -h --max-depth 1 76K ./dev 16G ./usr 4.0K ./lost+found
次に./usr配下で du -h --max-depth 1
240M ./lib64 15G ./local 21M ./sbin
次にlocal配下で du -h --max-depth 1
3.5M ./share 4.0K ./lib 14G ./mysql
次に ./mysql配下で du -h --max-depth 1
700K ./include 13G ./data 123M ./mysql-test 2.8M ./sql-bench
最初はログ系かなと思いきや、MySQLのデータそのものが容量オーバーしていた。。
ll /usr/local/mysql/data/ -rw-rw---- 1 mysql mysql 5242880 6月 21 10:49 ib_logfile0 -rw-rw---- 1 mysql mysql 5242880 6月 21 10:45 ib_logfile1 -rw-rw---- 1 mysql mysql 144703488 6月 21 10:49 ibdata1 drwxr-xr-x 2 mysql root 4096 1月 25 19:12 xxxx -rw-rw---- 1 mysql mysql 27338 1月 25 19:12 mysql-bin.000001 -rw-rw---- 1 mysql mysql 1029074 1月 25 19:12 mysql-bin.000002 -rw-rw---- 1 mysql mysql 126 1月 25 19:16 mysql-bin.000003 -rw-rw---- 1 mysql mysql 126 1月 25 19:27 mysql-bin.000004 -rw-rw---- 1 mysql mysql 5426372 1月 27 09:45 mysql-bin.000005 -rw-rw---- 1 mysql mysql 181523175 2月 3 14:40 mysql-bin.000006 -rw-rw---- 1 mysql mysql 759735 2月 3 16:24 mysql-bin.000007 -rw-rw---- 1 mysql mysql 1073743511 3月 2 00:50 mysql-bin.000008 -rw-rw---- 1 mysql mysql 1073742070 3月 12 01:15 mysql-bin.000009 -rw-rw---- 1 mysql mysql 1073745435 3月 20 15:58 mysql-bin.000010 -rw-rw---- 1 mysql mysql 1073741925 3月 30 04:05 mysql-bin.000011 -rw-rw---- 1 mysql mysql 1073743331 4月 8 01:35 mysql-bin.000012 -rw-rw---- 1 mysql mysql 1073741917 4月 17 01:45 mysql-bin.000013 -rw-rw---- 1 mysql mysql 1073742503 4月 24 12:20 mysql-bin.000014 -rw-rw---- 1 mysql mysql 1073744529 5月 2 08:37 mysql-bin.000015 -rw-rw---- 1 mysql mysql 1073742005 5月 12 01:30 mysql-bin.000016 -rw-rw---- 1 mysql mysql 1073743546 5月 20 23:23 mysql-bin.000017 -rw-rw---- 1 mysql mysql 37498720 5月 21 03:33 mysql-bin.000018 -rw-rw---- 1 mysql mysql 1073741878 5月 30 05:01 mysql-bin.000019 -rw-rw---- 1 mysql mysql 1073742000 6月 9 18:01 mysql-bin.000020 -rw-rw---- 1 mysql mysql 605347840 6月 21 09:22 mysql-bin.000021 -rw-rw---- 1 mysql mysql 589363 6月 21 10:03 mysql-bin.000022 -rw-rw---- 1 mysql mysql 2289476 6月 21 10:49 mysql-bin.000023 -rw-rw---- 1 mysql mysql 437 6月 21 10:03 mysql-bin.index drwx------ 2 mysql mysql 4096 1月 25 19:12 performance_schema drwx------ 2 mysql mysql 4096 4月 13 18:18 xxxx drwxr-xr-x 2 mysql root 4096 1月 25 18:26 xxxx
解決編
ということで、調べると定期的にバイナリログ(バックアップデータ)
を削除してくれる機能があるとのこと。設定してみた。
1.my.cnfを開く
vi /etc/my.cnf
2.log-binが記述されていることを確認。※なければ追記
# Replication Master Server (default) # binary logging is required for replication log-bin=mysql-bin
3.expire_logs_daysの設定を確認。ここが0になっていると削除しない設定。
mysql> SHOW GLOBAL VARIABLES like 'expire_logs_days'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | expire_logs_days | 0 | +------------------+-------+ 1 row in set (0.00 sec)
4.こんな感じで付け加える
# Replication Master Server (default) # binary logging is required for replication log-bin=mysql-bin expire_logs_days = 5
5.mysqldをリスタート。
/etc/init.d/mysqld restart ※restartできない場合はmysqlに入って直接SET GLOBAL expire_logs_days = 5;を実行
6.3をもういちど確認。
+------------------+-------+ | Variable_name | Value | +------------------+-------+ | expire_logs_days | 5 | +------------------+-------+
7.先ほど肥大化していたログを確認すると、既に古いバイナリログは削除されている。
ll /usr/local/mysql/data/
ついでにMySQLテーブルを見直し編
1.データベースのサイズを調べて、容量が多いもの順に並べるSQL
mysql> select table_schema, sum(data_length+index_length) /1024 /1024 as MB from information_schema.tables group by table_schema order by sum(data_length+index_length) desc; +--------------------+-------------+ | table_schema | MB | +--------------------+-------------+ | xxxxxx | 66.92219543 | | xxxxxx | 0.69593334 | | xxxxxx | 0.00878906 | | xxxxxx | 0.00000000 | +--------------------+-------------+
2.テーブルサイズを調べて、容量が多いもの順に並べるSQL
use xxxx; select table_name, engine, table_rows as tbl_rows, avg_row_length as rlen, floor((data_length+index_length)/1024/1024) as allMB, floor((data_length)/1024/1024) as dMB, floor((index_length)/1024/1024) as iMB from information_schema.tables where table_schema=database() order by (data_length+index_length) desc; +---------------------------+--------+----------+-------+-------+------+------+ | table_name | engine | tbl_rows | rlen | allMB | dMB | iMB | +---------------------------+--------+----------+-------+-------+------+------+ | xxxxxxxxxxxxxxxxxxxxxxxxxx| InnoDB | 138309 | 148 | 24 | 19 | 4 | | xxxxxxxxxxxxxxxxxxxxxxxxxx| InnoDB | 78230 | 73 | 12 | 5 | 7 | | xxxxxxxxxxxxxxxxxxxxxxxxxx| InnoDB | 35023 | 225 | 10 | 7 | 3 | | xxxxxxxxxxxxxxxxxxxxxxxxxx| InnoDB | 21450 | 416 | 8 | 8 | 0 | | xxxxxxxxxxxxxxxxxxxxxxxxxx| InnoDB | 15567 | 169 | 3 | 2 | 0 | | xxxxxxxxxxxxxxxxxxxxxxxxxx| MyISAM | 78 | 752 | 1 | 1 | 0 | | xxxxxxxxxxxxxxxxxxxxxxxxxx| InnoDB | 5712 | 278 | 1 | 1 | 0 |
3.消す
delete from messages where insert_date <= '2012-05-01';
(参考)
MySQLでバイナリログを定期的に削除するmy.cnfの設定(expire_logs_days)
http://d.hatena.ne.jp/omiyan/20110128/p1
全テーブルの統計情報をサイズ順に一覧表示する
http://opendatabaselife.blogspot.jp/2009/08/blog-post.html
MYSQL データベースサイズの確認
http://variable.jp/?p=1262