mysql-utilities工具体验

2024-03-25 12:38

本文主要是介绍mysql-utilities工具体验,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转载地址:http://yueliangdao0608.blog.51cto.com/397025/1199960


我主要体验了下几个关于REPLICATION的工具。 其他的可以参见手册。

先说下我的环境:

MASTER: 192.168.1.131

SLAVE: 192.168.1.132, 192.168.1.133

三台DB都有对外的ALL权限用户。

各个配置文件如下,


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@mysql56-master home]# cat /etc/my.cnf
[mysqld]
user = ytt
skip- name -resolve
innodb_buffer_pool_size = 128M
basedir = /usr/ local /mysql
datadir = /usr/ local /mysql/data
port = 3306
server_id = 131
socket = /tmp/mysql.sock
explicit_defaults_for_timestamp
log-bin=mysql56-master-bin
binlog- ignore -db=mysql
gtid-mode= on
enforce-gtid-consistency
log-slave-updates
binlog-format=ROW
sync-master-info=1
report-host=192.168.1.131
report-port=3306
master_info_repository= table
relay_log_info_repository= table


其他两台SERVER,除了SERVER-ID,都基本相同,我就不贴了。


1. MYSQLREPLICATE 搭建主从的脚本,这里我搭建了两台从机。


1
2
3
4
5
6
7
8
9
10
11
12
mysqlreplicate --master=root:root@192.168.1.131:3306 --slave=root:root@192.168.1.132:3306;...
[root@mysql56-master home]# ./replicate_create
# master on 192.168.1.131: ... connected.
# slave on 192.168.1.132: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.
# master on 192.168.1.131: ... connected.
# slave on 192.168.1.133: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.


2. mysqlrplcheck  检查主从的运行情况。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
[root@mysql56-master home]# mysqlrplcheck --master=root:root@192.168.1.131:3306 --slave=root:root@192.168.1.132:3306 -s
# master on 192.168.1.131: ... connected.
# slave on 192.168.1.132: ... connected.
Test Description                                                     Status
---------------------------------------------------------------------------
Checking for binary logging on master                                [pass]
Are there binlog exceptions?                                         [WARN]
+ ---------+--------+------------+
| server  | do_db  | ignore_db  |
+ ---------+--------+------------+
| master  |        | mysql      |
| slave   |        | mysql      |
+ ---------+--------+------------+
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]
#
# Slave status:
#
                 Slave_IO_State : Waiting for master to send event
                    Master_Host : 192.168.1.131
                    Master_User : rpl
                    Master_Port : 3306
                  Connect_Retry : 60
                Master_Log_File : mysql56-master-bin.000002
            Read_Master_Log_Pos : 151
                 Relay_Log_File : mysql56-slave-relay-bin.000003
                  Relay_Log_Pos : 379
          Relay_Master_Log_File : mysql56-master-bin.000002
               Slave_IO_Running : Yes
              Slave_SQL_Running : Yes
                Replicate_Do_DB :
            Replicate_Ignore_DB : mysql
             Replicate_Do_Table :
         Replicate_Ignore_Table :
        Replicate_Wild_Do_Table :
    Replicate_Wild_Ignore_Table :
                     Last_Errno : 0
                     Last_Error :
                   Skip_Counter : 0
            Exec_Master_Log_Pos : 151
                Relay_Log_Space : 819
                Until_Condition : None
                 Until_Log_File :
                  Until_Log_Pos : 0
             Master_SSL_Allowed : No
             Master_SSL_CA_File :
             Master_SSL_CA_Path :
                Master_SSL_Cert :
              Master_SSL_Cipher :
                 Master_SSL_Key :
          Seconds_Behind_Master : 0
  Master_SSL_Verify_Server_Cert : No
                  Last_IO_Errno : 0
                  Last_IO_Error :
                 Last_SQL_Errno : 0
                 Last_SQL_Error :
    Replicate_Ignore_Server_Ids :
               Master_Server_Id : 131
                    Master_UUID : 4d89ad1d-bc12-11e2-87e9-080027338857
               Master_Info_File : mysql.slave_master_info
                      SQL_Delay : 0
            SQL_Remaining_Delay : None
        Slave_SQL_Running_State : Slave has read all relay log; waiting for the slave I/O thread to update it
             Master_Retry_Count : 86400
                    Master_Bind :
        Last_IO_Error_Timestamp :
       Last_SQL_Error_Timestamp :
                 Master_SSL_Crl :
             Master_SSL_Crlpath :
             Retrieved_Gtid_Set :
              Executed_Gtid_Set :
                  Auto_Position : 1
# ...done.


3. mysqlrplshow. 显示主从的架构。


1
2
3
4
5
6
7
8
9
10
[root@mysql56-master home]# mysqlrplshow --master=root:root@192.168.1.131:3306 --discover-slaves-login=root:root -v
# master on 192.168.1.131: ... connected.
# Finding slaves for master: 192.168.1.131:3306
# Replication Topology Graph
192.168.1.131:3306 (MASTER)
    |
    + --- 192.168.1.132:3306 [IO running: Yes] - (SLAVE)
    |
    + --- 192.168.1.133:3306 [IO running: Yes] - (SLAVE)
[root@mysql56-master home]#



4. mysqlfailover. 监视主从健康状态。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@mysql56-master home]# mysqlfailover --master=root:root@192.168.1.131:3306 --discover-slaves-login=root:root
# Discovering slaves for master at 192.168.1.131:3306
# Discovering slave at 192.168.1.132:3306
# Found slave: 192.168.1.132:3306
# Discovering slave at 192.168.1.133:3306
# Found slave: 192.168.1.133:3306
# Checking privileges .
MySQL Replication Failover Utility
Failover Mode = auto     Next Interval = Tue May 14 12:27:56 2013
Master Information
------------------
Binary Log File       Position  Binlog_Do_DB  Binlog_Ignore_DB
mysql56-master-bin.0  151                     mysql           
GTID Executed Set
None
Replication Health Status
+ ----------------+-------+---------+--------+------------+-------------------------------------------+
| host           | port  | role    | state  | gtid_mode  | health                                    |
+ ----------------+-------+---------+--------+------------+-------------------------------------------+
| 192.168.1.131  | 3306  | MASTER  | UP     | ON         | OK                                        |
| 192.168.1.132  | 3306  | SLAVE   | UP     | ON         | OK                                        |
| 192.168.1.133  | 3306  | SLAVE   | UP     | ON         | Binary log and Relay log filters differ.  |
+ ----------------+-------+---------+--------+------------+-------------------------------------------+
Q-quit R-refresh H-health G-GTID Lists U-UUIDs
[root@mysql56-master home]#



5. mysqlrpladmin. 对主从进行管理。

停止从机服务:

1
2
3
4
5
6
7
[root@mysql56-master home]# mysqlrpladmin  --master=root:root@192.168.1.131:3306 --slaves=root:root@192.168.1.132:3306,root:root@192.168.1.133:3306  stop
# Checking privileges .
# Performing STOP on all slaves.
#   Executing stop on slave 192.168.1.132:3306 Ok
#   Executing stop on slave 192.168.1.133:3306 Ok
# ...done.
[root@mysql56-master home]#

开启从机服务:

1
2
3
4
5
6
7
[root@mysql56-master home]# mysqlrpladmin  --master=root:root@192.168.1.131:3306 --slaves=root:root@192.168.1.132:3306,root:root@192.168.1.133:3306  stop
# Checking privileges .
# Performing STOP on all slaves.
#   Executing stop on slave 192.168.1.132:3306 Ok
#   Executing stop on slave 192.168.1.133:3306 Ok
# ...done.
[root@mysql56-master home]#


选择最好的备机准备以后切换用.

1
2
3
4
5
6
[root@mysql56-master home]# mysqlrpladmin --master=root:root@192.168.1.131:3306 --slaves=root:root@192.168.1.132:3306,root:root@192.168.1.133:3306 elect
# Checking privileges .
# Electing candidate slave from known slaves.
# Best slave found is located on 192.168.1.132:3306.
# ...done.
[root@mysql56-master home]#

进行主从切换。



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@mysql56-master home]#  mysqlrpladmin --master=root:root@192.168.1.131:3306 --slaves=root:root@192.168.1.132:3306,root:root@192.168.1.133:3306  --new-master=root:root@192.168.1.132:3306  --demote-master switchover  
# Checking privileges .
# Performing switchover from master at 192.168.1.131:3306 to slave at 192.168.1.132:3306.
# Checking candidate slave prerequisites.
# Checking slaves configuration to master.
# Waiting for slaves to catch up to old master.
# Stopping slaves.
# Performing STOP on all slaves.
# Demoting old master to be a slave to the new master.
# Switching slaves to new master.
# Starting all slaves.
# Performing START on all slaves.
# Checking slaves for errors.
# Switchover complete.
#
# Replication Topology Health:
+ ----------------+-------+---------+--------+------------+-----------------------------+
| host           | port  | role    | state  | gtid_mode  | health                      |
+ ----------------+-------+---------+--------+------------+-----------------------------+
| 192.168.1.132  | 3306  | MASTER  | UP     | ON         | OK                          |
| 192.168.1.131  | 3306  | SLAVE   | UP     | ON         | OK                          |
| 192.168.1.133  | 3306  | SLAVE   | UP     | ON         | OK                          |
+ ----------------+-------+---------+--------+------------+-----------------------------+
# ...done.
[root@mysql56-master home]#


显示下新的主从架构:


1
2
3
4
5
6
7
8
9
10
[root@mysql56-master home]# mysqlrplshow --master=root:root@192.168.1.132:3306 --discover-slaves-login=root:root -v
# master on 192.168.1.132: ... connected.
# Finding slaves for master: 192.168.1.132:3306
# Replication Topology Graph
192.168.1.132:3306 (MASTER)
    |
    + --- 192.168.1.131:3306 [IO running: Yes] - (SLAVE)
    |
    + --- 192.168.1.133:3306 [IO running: Yes] - (SLAVE)
[root@mysql56-master home]#


本文出自 “上帝,咱们不见不散!” 博客,请务必保留此出处http://yueliangdao0608.blog.51cto.com/397025/1199960


这篇关于mysql-utilities工具体验的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/845038

相关文章

SQL server数据库如何下载和安装

《SQLserver数据库如何下载和安装》本文指导如何下载安装SQLServer2022评估版及SSMS工具,涵盖安装配置、连接字符串设置、C#连接数据库方法和安全注意事项,如混合验证、参数化查... 目录第一步:打开官网下载对应文件第二步:程序安装配置第三部:安装工具SQL Server Manageme

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.

全面掌握 SQL 中的 DATEDIFF函数及用法最佳实践

《全面掌握SQL中的DATEDIFF函数及用法最佳实践》本文解析DATEDIFF在不同数据库中的差异,强调其边界计算原理,探讨应用场景及陷阱,推荐根据需求选择TIMESTAMPDIFF或inte... 目录1. 核心概念:DATEDIFF 究竟在计算什么?2. 主流数据库中的 DATEDIFF 实现2.1

MySQL 多列 IN 查询之语法、性能与实战技巧(最新整理)

《MySQL多列IN查询之语法、性能与实战技巧(最新整理)》本文详解MySQL多列IN查询,对比传统OR写法,强调其简洁高效,适合批量匹配复合键,通过联合索引、分批次优化提升性能,兼容多种数据库... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析

MySQL中的LENGTH()函数用法详解与实例分析

《MySQL中的LENGTH()函数用法详解与实例分析》MySQLLENGTH()函数用于计算字符串的字节长度,区别于CHAR_LENGTH()的字符长度,适用于多字节字符集(如UTF-8)的数据验证... 目录1. LENGTH()函数的基本语法2. LENGTH()函数的返回值2.1 示例1:计算字符串

浅谈mysql的not exists走不走索引

《浅谈mysql的notexists走不走索引》在MySQL中,​NOTEXISTS子句是否使用索引取决于子查询中关联字段是否建立了合适的索引,下面就来介绍一下mysql的notexists走不走索... 在mysql中,​NOT EXISTS子句是否使用索引取决于子查询中关联字段是否建立了合适的索引。以下

Python办公自动化实战之打造智能邮件发送工具

《Python办公自动化实战之打造智能邮件发送工具》在数字化办公场景中,邮件自动化是提升工作效率的关键技能,本文将演示如何使用Python的smtplib和email库构建一个支持图文混排,多附件,多... 目录前言一、基础配置:搭建邮件发送框架1.1 邮箱服务准备1.2 核心库导入1.3 基础发送函数二、

Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式

《Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式》本文详细介绍如何使用Java通过JDBC连接MySQL数据库,包括下载驱动、配置Eclipse环境、检测数据库连接等关键步骤,... 目录一、下载驱动包二、放jar包三、检测数据库连接JavaJava 如何使用 JDBC 连接 mys

SQL中如何添加数据(常见方法及示例)

《SQL中如何添加数据(常见方法及示例)》SQL全称为StructuredQueryLanguage,是一种用于管理关系数据库的标准编程语言,下面给大家介绍SQL中如何添加数据,感兴趣的朋友一起看看吧... 目录在mysql中,有多种方法可以添加数据。以下是一些常见的方法及其示例。1. 使用INSERT I

Qt使用QSqlDatabase连接MySQL实现增删改查功能

《Qt使用QSqlDatabase连接MySQL实现增删改查功能》这篇文章主要为大家详细介绍了Qt如何使用QSqlDatabase连接MySQL实现增删改查功能,文中的示例代码讲解详细,感兴趣的小伙伴... 目录一、创建数据表二、连接mysql数据库三、封装成一个完整的轻量级 ORM 风格类3.1 表结构