Scenario
MySQL database master copy is automatically deleted from the default library in the relay logs after the SQL thread is finished. But: In relay_log_purge = 0 and MHA cluster it will not be automatically deleted need to be deleted manually. How safe to delete relay logs on the more critical!
There are two main ways:
One way:
to delete by MHA comes with the tool purge_relay_logs tool.
step:
- Create a working directory
Objective To improve performance, the working directory must be on the same disk partition with mysql
mkdir -p /data/mha_tmp
- purge relay logs
/usr/bin/purge_relay_logs --user=USERNAME --password=PASSWORD --host=Mysql_IP --disable_relay_log_purge --workdir=/data/mha_tmp 2>&1
- Added to the crontab
0 4 * * * /usr/bin/purge_relay_logs --user=USERNAME --password=PASSWORD --host=Mysql_IP --disable_relay_log_purge --workdir=/data/mha_tmp 2>&1
Description:
-disable_relay_log_purge: Auto Set "relay_log_purge = 1"
Second way:
Manually delete the relay log
- Provided relay_log_purge = 1
SET GLOBAL relay_log_purge = 1
- flush logs
log in through the Administrator user from the database, and then execute the following command:
flush logs;
You can perform multiple!
Note :
if the observed accumulation of relay logs logs have been deleted, if deleted, the direct implementation of the following Step 6 "recovery relay_log_purge = 0"; if not removed, continue to "stop slave" from below step 3 down operation! ! !
- Stop slave
landed from the database by an administrator user, and then execute the following command:
stop slave;
- Delete relay logs
can be deleted directly by rm relay logs
through the use of secure delete the following way:
The total number (1) All documents on the relay's statistics (including relay_log_name.index)
ls -A1 |grep relay | sort -rn | wc -l
(2) 列出要删除所有有关relay的文件:
ls -A1 |grep relay | sort -rn | tail -n 100
说明: 100 为要删除的relay logs 数量
(3) 确定没有问题,删除relay logs:
ls -A1 |grep relay | sort -rn | tail -n 100 | xargs rm -rf {}
注意:
要保留最新的两个relay log
要保留relay log的index文件
relay log的index一般命名为: relay_log_name.index
例如: relay-bin.index
5. 启动slave
通过管理员用户登陆从数据库,然后执行下面命令:
start slave;
6 . 恢复relay_log_purge = 0
通过管理员用户登陆从数据库,然后执行下面命令:
SET GLOBAL relay_log_purge=0;
扩展
如果你对从数据库要求不高,可以将relay_log_purge = 1