MySQL Utilities之高可用层面常用命令

1.1 mysqlfailover

  对复制进行健康检测和实现故障自动转移
需要gtid_mode=ON
所有从必需使用–report-host 和 --report-port 启动参数

–failover-mode
auto 执行故障自动转移到第一候选人
elect 与auto一样,但若在指定候选从列表中没有可行的,不检查剩余从,产生错误并退出
fail 产生一个错误,不进行故障转移

[root@zijie ~]# mysqlfailover --master=root:[email protected]:3306 --discover-slaves-login=root:970125 --candidates=root:[email protected]:3308,root:[email protected]:3309
WARNING: Using a password on the command line interface can be insecure.
# Discovering slaves for master at 127.0.0.1:3306
# Discovering slave at 127.0.0.1:3308
# Found slave: 127.0.0.1:3308
# Discovering slave at 127.0.0.1:3309
# Found slave: 127.0.0.1:3309
# Checking privileges.
# Checking privileges on candidates.
MySQL Replication Failover Utility
Failover Mode = auto     Next Interval = Thu Jul 30 22:42:08 2020

Master Information
------------------
Binary Log File  Position  Binlog_Do_DB  Binlog_Ignore_DB
mybinlog.000002  1682

GTID Executed Set
96b3ca32-d268-11ea-a39e-00163e0c8a51:1-6

Replication Health Status
+------------+-------+---------+--------+------------+---------+
| host       | port  | role    | state  | gtid_mode  | health  |
+------------+-------+---------+--------+------------+---------+
| 127.0.0.1  | 3306  | MASTER  | UP     | ON         | OK      |
| 127.0.0.1  | 3308  | SLAVE   | UP     | ON         | OK      |
| 127.0.0.1  | 3309  | SLAVE   | UP     | ON         | OK      |
+------------+-------+---------+--------+------------+---------+
Q-quit R-refresh H-health G-GTID Lists U-UUIDs
2020-07-30T14:43:12.745882Z mysqld_safe mysqld from pid file /data/mysql57/data/mysql.pid ended
Failed to reconnect to the master after 3 attemps.
Failover starting in 'auto' mode...
# Candidate 127.0.0.1:3308 does not meet the requirements.
# Candidate slave 127.0.0.1:3309 will become the new master.
# Checking slaves status (before failover).
# Preparing candidate for failover.
# Creating replication user if it does not exist.
# Stopping slaves.
# Performing STOP on all slaves.
# Switching slaves to new master.
# Disconnecting new master as slave.
# Starting slaves.
# Performing START on all slaves.
# Checking slaves for errors.
# Failover complete.
# Discovering slaves for master at 127.0.0.1:3309

Failover console will restart in 5 seconds.

MySQL Replication Failover Utility
Failover Mode = auto     Next Interval = Thu Jul 30 22:43:47 2020

Master Information
------------------
Binary Log File   Position  Binlog_Do_DB  Binlog_Ignore_DB
mysql-bin.000002  154

GTID Executed Set
96b3ca32-d268-11ea-a39e-00163e0c8a51:1-6

Replication Health Status
+------------+-------+---------+--------+------------+---------+
| host       | port  | role    | state  | gtid_mode  | health  |
+------------+-------+---------+--------+------------+---------+
| 127.0.0.1  | 3309  | MASTER  | UP     | ON         | OK      |
| 127.0.0.1  | 3308  | SLAVE   | UP     | ON         | OK      |
+------------+-------+---------+--------+------------+---------+

1.2 mysqlreplicate

  在两台服务器间设置和启动复制

[root@zijie ~]# mysqlreplicate --master=master57 --slave=slave57 --rpl-user=repl:repl -b
# master on 127.0.0.1: ... connected.
# slave on 127.0.0.1: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.

1.3 mysqlrplms

  设置多主单从的复制,即从多个主复制

[root@zijie ~]# mysqlrplms --slave=root:970125@localhost:/data/tmp/mysql.sock --masters=root:[email protected]:3306,root:[email protected]:3308 --rpl-user=repl:repl
WARNING: Using a password on the command line interface can be insecure.
# Starting multi-source replication...
# Press CTRL+C to quit.
# Switching to master '127.0.0.1:3306'.
# master on 127.0.0.1: ... connected.
# slave on localhost: ... connected.
2020-07-30T13:58:46.608531Z 18 [Note] Error reading relay log event for channel '': slave SQL thread was killed
2020-07-30T13:58:46.608552Z 18 [Note] Slave SQL thread for channel '' exiting, replication stopped in log 'mybinlog.000002' at position 1682
2020-07-30T13:58:46.609839Z 17 [Note] Slave I/O thread killed while reading event for channel ''
2020-07-30T13:58:46.609852Z 17 [Note] Slave I/O thread exiting for channel '', read up to log 'mybinlog.000002', position 1682
2020-07-30T13:58:46.613272Z 23 [Note] 'CHANGE MASTER TO FOR CHANNEL '' executed'. Previous state master_host='127.0.0.1', master_port= 3306, master_log_file='mybinlog.000002', master_log_pos= 1682, master_bind=''. New state master_host='127.0.0.1', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''.
2020-07-30T13:58:46.626836Z 24 [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2020-07-30T13:58:46.627191Z 24 [Note] Slave I/O thread for channel '': connected to master '[email protected]:3306',replication started in log 'FIRST' at position 4
2020-07-30T13:58:46.628046Z 25 [Warning] Slave SQL for channel '': If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
2020-07-30T13:58:46.628065Z 25 [Note] Slave SQL thread for channel '' initialized, starting replication in log 'FIRST' at position 0, relay log './zijie-relay-bin.000001' position: 4
# WARNING: You may be mixing host names and IP addresses. This may result in negative status reporting if your DNS services do not support reverse name lookup.
#
# Current Master Information:
+------------------+-----------+---------------+-------------------+
| Binary Log File  | Position  | Binlog_Do_DB  | Binlog_Ignore_DB  |
+------------------+-----------+---------------+-------------------+
| mybinlog.000002  | 1682      | N/A           | N/A               |
+------------------+-----------+---------------+-------------------+
# GTID Executed Set: 96b3ca32-d268-11ea-a39e-00163e0c8a51:1-6
#
# Health Status:
+------------+-------+---------+--------+------------+---------+
| host       | port  | role    | state  | gtid_mode  | health  |
+------------+-------+---------+--------+------------+---------+
| 127.0.0.1  | 3306  | MASTER  | UP     | ON         | OK      |
| localhost  | 3309  | SLAVE   | UP     | ON         | OK      |
| 127.0.0.1  | 3308  | MASTER  | UP     | ON         | OK      |
+------------+-------+---------+--------+------------+---------+

1.4 mysqlrpladmin

  MySQL复制的管理工具

[root@zijie mysql57slave]#  mysqlrpladmin --master=master57 --slaves=slave57 health
# Checking privileges.
#
# Replication Topology Health:
+------------+-------+---------+--------+------------+---------+
| host       | port  | role    | state  | gtid_mode  | health  |
+------------+-------+---------+--------+------------+---------+
| 127.0.0.1  | 3306  | MASTER  | UP     | ON         | OK      |
| 127.0.0.1  | 3308  | SLAVE   | UP     | ON         | OK      |
+------------+-------+---------+--------+------------+---------+
# ...done.

1.5 mysqlrplcheck

  检查复制的先决条件

[root@zijie test]# mysqlrplcheck --master=master57 --slave=slave57
# master on 127.0.0.1: ... connected.
# slave on 127.0.0.1: ... connected.
Test Description                                                     Status
---------------------------------------------------------------------------
Checking for binary logging on master                                [pass]
Are there binlog exceptions?                                         [pass]
Replication user exists?                                             [pass]
Checking server_id values                                            [pass]
Checking server_uuid values                                          [pass]
Is slave connected to master?                                        [pass]
Check master information file                                        [pass]
Checking InnoDB compatibility                                        [pass]
Checking storage engines compatibility                               [pass]
Checking lower_case_table_names settings                             [pass]
Checking slave delay (seconds behind master)                         [pass]
# ...done.

1.6 mysqlrplshow

  显示主从复制关系,并绘制主的图形结构,标注每个主机名和端口

[root@zijie test]# mysqlrplshow --master=root:970125@localhost:/data/mysql57/data/mysql57.sock --discover-slaves-login=root:970125 --verbose
WARNING: Using a password on the command line interface can be insecure.
# master on localhost: ... connected.
# Finding slaves for master: localhost:3306

# Replication Topology Graph
localhost:3306 (MASTER)
   |
   +--- 127.0.0.1:3308 [IO: Yes, SQL: Yes] - (SLAVE)

1.7 mysqlrplsync

  对复制同步进行检查,检查主从或从从之间的数据是否一致,并报告丢失的对象以及数据

[root@zijie test]# mysqlrplsync --master=master57 --slaves=slave57 zijie
#
# GTID differences between Master and Slaves:
# - Slave '127.0.0.1@3308' is 4 transactions behind Master.
#
# Checking data consistency.
#
# Using Master '127.0.0.1@3306' as base server for comparison.
# Checking 'zijie' database...
# - Checking 't1' table data...
#   WARNING: Slave not active '127.0.0.1@3308' - Sync skipped.
#   [OK] `zijie`.`t1` checksum for server '127.0.0.1@3308'.
#   [DIFF] Table 'zijie.t2' NOT on server '127.0.0.1@3308'.
# - Checking 't_access' table data...
#   WARNING: Slave not active '127.0.0.1@3308' - Sync skipped.
#   [OK] `zijie`.`t_access` checksum for server '127.0.0.1@3308'.
#
#...done.
#
# SUMMARY: 1 data consistency issue found.
#


[root@zijie test]# mysqlrplsync --master=master57 --slaves=slave57 zijie
#
# GTID differences between Master and Slaves:
# - Slave '127.0.0.1@3308' is up-to-date.
#
# Checking data consistency.
#
# Using Master '127.0.0.1@3306' as base server for comparison.
# Checking 'zijie' database...
# - Checking 't1' table data...
#   [OK] `zijie`.`t1` checksum for server '127.0.0.1@3308'.
# - Checking 't2' table data...
#   [OK] `zijie`.`t2` checksum for server '127.0.0.1@3308'.
# - Checking 't_access' table data...
#   [OK] `zijie`.`t_access` checksum for server '127.0.0.1@3308'.
#
#...done.
#
# SUMMARY: No data consistency issue found.
#

猜你喜欢

转载自blog.csdn.net/qq_42979842/article/details/107702972