【MySQL日常管理】调整binlog和relaylog路径

迁移前的路径:
binlog: /u01/mysql/logs
relaylog :/u01/mysql/logs

迁移的目标路径:
binlog: /nasbackup/logs
relaylog :/nasbackup/logs

一、主库迁移binlog日志

在可停库的场景下:
1、首先停止mysql
2、复制所有binlog到目的磁盘:/nasbackup/logs/mysql-bin.* 同时要复制mysql-bin.index到新路径
3、修改my.cnf配置文件
log-bin=/nasbackup/logs/mysql-bin
4、编辑 mysql-bin.index
把内容修改为绝对路径:
/nasbackup/logs/mysql-bin.000001
/nasbackup/logs/mysql-bin.000002
/nasbackup/logs/mysql-bin.000003
/nasbackup/logs/mysql-bin.000004
5、启动mysql
/etc/init.d/mysql start 

二、从库迁移relay log 

  • 可停库的场景

1、首先停止mysql
2、把relaylog 迁移到目标路径,/nasbackup/logs/relay-bin.* 同时迁移 relay-bin.index
3、同时在my.cnf中增加一条
relay_log=/nasbackup/logs/relay-bin.log
4、然后编辑 relay-bin.index 把路径改为新的日志路径 /nasbackup/logs/relay-bin.*
5、编辑 relay-log.info文件,改为新的日志路径
6、启动mysql
/ett/init.d/mysql start

  • 在线调整

 

修改备库relay log目录路径
mysql> show variables like '%relay_log%';
+---------------------------+---------------------------------+
| Variable_name | Value |
+---------------------------+---------------------------------+
| max_relay_log_size | 0 |
| relay_log | /u01/mysql/logs/relay-bin |
| relay_log_basename | /u01/mysql/logs/relay-bin |
| relay_log_index | /u01/mysql/logs/relay-bin.index |
| relay_log_info_file | relay-log.info |
| relay_log_info_repository | TABLE |
| relay_log_purge | ON |
| relay_log_recovery | ON |
| relay_log_space_limit | 0 |
| sync_relay_log | 0 |
| sync_relay_log_info | 0 |
+---------------------------+---------------------------------+
11 rows in set (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.172.160.1
Master_User: repl
Master_Port: 27415
Connect_Retry: 60
Master_Log_File: master-bin.013433
Read_Master_Log_Pos: 479752088
Relay_Log_File: relay-bin.018578
Relay_Log_Pos: 242548984
Relay_Master_Log_File: master-bin.006193
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
mysql> stop slave io_thread;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 10.172.160.1
Master_User: repl
Master_Port: 27415
Connect_Retry: 60
Master_Log_File: master-bin.013433
Read_Master_Log_Pos: 479803644
Relay_Log_File: relay-bin.018578
Relay_Log_Pos: 242548984
Relay_Master_Log_File: master-bin.006193
Slave_IO_Running: No
Slave_SQL_Running: Yes
mysql> stop slave sql_thread;
mysql> show processlist;

mysql> show processlist;
+--------+-------------+-----------+-----------+---------+---------+---------------------------------------------+--------------------------------------------------+
| Id     | User        | Host      | db        | Command | Time    | State                                       | Info                     |
+--------+-------------+-----------+-----------+---------+---------+---------------------------------------------+------------------------------------------------------------------------------------------------------+
| 168798 | system user |           | NULL      | Connect |     364 | Waiting for dependent transaction to commit | NULL                     |
| 168799 | system user |           | zeze_test | Connect | 2397319 | Creating sort index                         | INSERT INTO apps.garden_order_details(company_id
| 168800 | system user |           | NULL      | Connect | 2396990 | Waiting for an event from Coordinator       | NULL                     |
| 168801 | system user |           | NULL      | Connect | 2397518 | Waiting for an event from Coordinator       | NULL                     |
| 168802 | system user |           | NULL      | Connect | 2398077 | Waiting for an event from Coordinator       | NULL                     |
| 168803 | system user |           | NULL      | Connect | 2398480 | Waiting for an event from Coordinator       | NULL                     |
| 168804 | system user |           | NULL      | Connect | 2398480 | Waiting for an event from Coordinator       | NULL                     |
| 168805 | system user |           | NULL      | Connect | 2401247 | Waiting for an event from Coordinator       | NULL                     |
| 168806 | system user |           | NULL      | Connect | 2464888 | Waiting for an event from Coordinator       | NULL                     |
| 168807 | system user |           | NULL      | Connect | 2464888 | Waiting for an event from Coordinator       | NULL                     |
| 168808 | system user |           | NULL      | Connect |  736006 | Waiting for an event from Coordinator       | NULL                     |
| 242171 | admin       | localhost | NULL      | Query   |      50 | Killing slave                               | stop slave  sql_thread   |
| 242208 | admin       | localhost | NULL      | Query   |       0 | starting                                    | show processlist         |
+--------+-------------+-----------+-----------+---------+---------+---------------------------------------------+-------------------------------------------------+
13 rows in set (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 10.172.160.1
Master_User: repl
Master_Port: 27415
Connect_Retry: 60
Master_Log_File: master-bin.013433
Read_Master_Log_Pos: 479803644
Relay_Log_File: relay-bin.018578
Relay_Log_Pos: 242568557
Relay_Master_Log_File: master-bin.006193
Slave_IO_Running: No
Slave_SQL_Running: No
[mysql@p0-slave-db02 mysql]$ cd /u01/mysql/
[mysql@p0-slave-db02 mysql]$ du -sh *
2.5G base
4.7T data
12K init.d
3.5T logs
12K run
4.0K tmp
[mysql@p0-slave-db02 mysql]$ mv logs /nasbackup/
[mysql@p0-slave-db02 mysql]
创建软连接:
ln -s 源目录/文件 目地目录/文件
ln -s /nasbackup/logs logs
在relaylog目录下创建软连接
[mysql@p0-slave-db02 mysql]

mysql> start slave sql_thread;

mysql> start slave io_thead;

mysql> show slave status\G;

 

posted on 2022-05-11 21:30  HelonTian  阅读(1531)  评论(0编辑  收藏  举报