主从复制监控
以下命令在主库运行
#查看向从库发送binlog的状态,repl为复制账号,线程为Binlog Dump
mysql> show processlist;
+----+------+--------------------+------+-------------+-------+---------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+--------------------+------+-------------+-------+---------------------------------------------------------------+------------------+
| 70 | root | localhost | NULL | Query | 0 | starting | show processlist |
| 72 | repl | 10.154.0.112:60650 | NULL | Binlog Dump | 27877 | Master has sent all binlog to slave; waiting for more updates | NULL |
+----+------+--------------------+------+-------------+-------+---------------------------------------------------------------+------------------+
2 rows in set (0.00 sec)
#查看主库使用的binlog日志以及记录的Position号,用于判断是否有数据写入
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------------------------------------------------------------------------+
| mysql-bin.000041 | 1070 | | | 3d111a50-9355-11eb-b573-000c29a2912e:1-4,
65c12fe4-613e-11eb-9271-000c29a2912e:1-23 |
+------------------+----------+--------------+------------------+-------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
#可以查看从库的端口,server_id,master_id,以及uuid信息
mysql> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID |
+-----------+------+------+-----------+--------------------------------------+
| 7 | | 3306 | 6 | 608b0578-8b03-11eb-a172-000c290d40be |
+-----------+------+------+-----------+--------------------------------------+
1 row in set (0.00 sec)
以下命令在从库运行
mysql> show slave status G
#以下信息是关于主库有关的信息,来自于master.info文件
Master_Host: 10.154.0.111
Master_User: repl
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000041 #获取到的binlog文件名
Read_Master_Log_Pos: 752 #获取到的位置点信息
#以下信息是关于从库relay-log执行情况,来自于relay-log.info文件
Relay_Log_File: client2-relay-bin.000005 #该文件对应mysql-bin.000041日志文件
Relay_Log_Pos: 320 #已经执行到的位置点
Relay_Master_Log_File: mysql-bin.000041
Exec_Master_Log_Pos: 1070 #已经执行到的主库的位置点信息
#以下为从库的线程状态
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
#以下为具体报错信息,用于排错
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
#过滤复制有关的信息,用于只主从复制部分数据库时使用
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
#从库延时主库的时间,也就是主从复制落后主库多少秒,是不可抗力的例如网络延迟造成的延时
Seconds_Behind_Master: 0
#延时从库的配置信息,用于防止主库误删数据,延时从主库同步,是人为指定延时
SQL_Delay: 0
SQL_Remaining_Delay: NULL
#GTID相关的复制信息
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
主从的线程管理
mysql> start slave; #启动所有线程
mysql> stop slave; #关闭所有线程
mysql> start slave sql_thread; #单独启动sql线程
mysql> start slave io_thread; #单独启动io线程
mysql> stop slave sql_thread; #单独关闭sql线程
mysql> stop slave io_thread; #单独关闭io线程
解除从库身份,前提是io跟sql线程关闭,一般用于重新搭建主从环境,会清除CHANGE MASTER TO
的信息
mysql> reset slave all;
mysql> show slave status G #清除后从库无信息显示