MySQL管理利器 MySQL Utilities---mysqlreplicate

mysqlreplicate  工具是在两台服务器间设置和启动复制。用户提供登录从服务器信息和连接到主的信息。也可以指定一个数据库用于测试复制。

该工具报告条件是当主和从的存储引擎不一样时。如果主和从的存储引擎不同将产生告警信息。对于Innodb存储引擎而言,必需完全一样,Innodb的类型(built-in 或 InnoDB Plugin)需要一样,同时主次版本号也要一样,并启用状态。

默认情况下,该工具的警告问题在于下面的信息不匹配,存储引擎设置、默认存储引擎和Innodb存储引擎。为了使用错误代替警告,使用 --pedantic 选项来要求主从存储引擎必需一直。

为了查看存储引擎和innodb值之间的差异,可以使用-vv选项,不管有没使用--pedantic选项。

可以使用下面的策略启动复制:

  • Start from the current position (default)

    从当前的主二进制日志和位置开始复制。该工具使用SHOW MASTER STATUS语句来获取这些信息。

  • Start from the beginning

    从主二进制日志中记录的第一个事件开始复制。使用 --start-from-beginning 选项。

  • Start from a binary log file

    从指定的主二进制日志的第一个事件开始复制。使用 --master-log-file 选项。

  • Start from a specific event

    从特定的事件坐标开始复制 (特定的二进制日志和位置)。使用 --master-log-file 和 --master-log-pos 选项。

选项

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

MySQL Utilities mysqlreplicate version 1.5.3

License type: GPLv2

Usage: mysqlreplicate --master=root@localhost:3306 --slave=root@localhost:3310 --rpl-user=rpl:passwd

mysqlreplicate - establish replication with a master

Options:

  --version             show program's version number and exit

  --help                display a help message and exit

  --license             display program's license and exit

  --master=MASTER       connection information for master server in the form:

                        <user>[:<password>]@<host>[:<port>][:<socket>] or

                        <login-path>[:<port>][:<socket>] or <config-

                        path>[<[group]>].

  --slave=SLAVE         connection information for slave server in the form:

                        <user>[:<password>]@<host>[:<port>][:<socket>] or

                        <login-path>[:<port>][:<socket>] or <config-

                        path>[<[group]>].

  --rpl-user=RPL_USER   the user and password for the replication user

                        requirement, in the form: <user>[:<password>] or

                        <login-path>. E.g. rpl:passwd

  -p, --pedantic        fail if storage engines differ among master and slave.

  --test-db=TEST_DB     database name to use in testing replication setup

                        (optional)如果没有给出这个选项,不进行任何测试,只进行错误检查。

  --master-log-file=MASTER_LOG_FILE

                        use this master log file to initiate the slave.

  --master-log-pos=MASTER_LOG_POS

                        use this position in the master log file to initiate

                        the slave.与--master-log-file选项同时使用有效。

  -b, --start-from-beginning

                        start replication from the first event recorded in the

                        binary logging of the master. Not valid with --master-

                        log-file or --master-log-pos. 与--master-log-file 和

                        --master-log-pos 同时使用才有效。

  --ssl-ca=SSL_CA       The path to a file that contains a list of trusted SSL

                        CAs.

  --ssl-cert=SSL_CERT   The name of the SSL certificate file to use for

                        establishing a secure connection.

  --ssl-key=SSL_KEY     The name of the SSL key file to use for establishing a

                        secure connection.

  -v, --verbose         control how much information is displayed. e.g., -v =

                        verbose, -vv = more verbose, -vvv = debug

  -q, --quiet           turn off all messages for quiet execution.

注意事项

登录主服务器的用户必须具有对访问数据库的授权权限和创建账号的权限。也就是WITH GRANT OPTION 权限。

主和从的server ID必须非零和唯一的。如果为0或相同产生错误报告。

IP地址和主机名混合使用不推荐。涉及到反向解析的问题。

MySQL客户端工具的路径需要包含在PATH环境变量中,以便使用login-paths验证机制。允许使用my_print_defaults 来从登陆配置文件(.mylogin.cnf)读取login-path值。

实例

在同一台服务器上使用相同的默认设置不同端口的两个实例的复制,命令如下:

1

2

3

4

5

6

7

shell> mysqlreplicate --master=root@localhost:3306 \

          --slave=root@localhost:3307 --rpl-user=rpl:rpl

# master on localhost: ... connected.

# slave on localhost: ... connected.

# Checking for binary logging on master...

# Setting up replication...

# ...done.

使用 --pedantic选项来确保主和从复制成功,当且仅当两个服务器具有相同的存储引擎,相同的默认存储引擎和相同的InnoDB存储引擎。如下所示:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

shell> mysqlreplicate --master=root@localhost:3306 \

          --slave=root@localhost:3307 --rpl-user=rpl:rpl -vv --pedantic

# master on localhost: ... connected.

# slave on localhost: ... connected.

# master id = 2

#  slave id = 99

# Checking InnoDB statistics for type and version conflicts.

# Checking storage engines...

# Checking for binary logging on master...

# Setting up replication...

# Flushing tables on master with read lock...

# Connecting slave to master...

# CHANGE MASTER TO MASTER_HOST = [...omitted...]

# Starting slave...

# status: Waiting for master to send event

# error: 0:

# Unlocking tables on master...

# ...done.

从当前主的位置开始复制,默认的。如下所示:

1

2

3

4

5

6

7

shell> mysqlreplicate --master=root@localhost:3306 \

          --slave=root@localhost:3307 --rpl-user=rpl:rpl

# master on localhost: ... connected.

# slave on localhost: ... connected.

# Checking for binary logging on master...

# Setting up replication...

# ...done.

从主记录的事件开始复制,如下所示:

1

2

3

4

5

6

7

8

shell> mysqlreplicate --master=root@localhost:3306 \

     --slave=root@localhost:3307 --rpl-user=rpl:rpl \

     --start-from-beginning

# master on localhost: ... connected.

# slave on localhost: ... connected.

# Checking for binary logging on master...

# Setting up replication...

# ...done.

从特定的主二进制日志开始复制,如下所示:

1

2

3

4

5

6

7

8

shell> mysqlreplicate --master=root@localhost:3306 \

          --slave=root@localhost:3307 --rpl-user=rpl:rpl \

          --master-log-file=my_log.000003

# master on localhost: ... connected.

# slave on localhost: ... connected.

# Checking for binary logging on master...

# Setting up replication...

# ...done.

从特定的主二进制日志坐标开始复制(指定二进制文件和位置),如下所示:

1

2

3

4

5

6

7

8

shell> mysqlreplicate --master=root@localhost:3306 \

          --slave=root@localhost:3307 --rpl-user=rpl:rpl \

          --master-log-file=my_log.000001 --master-log-pos=96

# master on localhost: ... connected.

# slave on localhost: ... connected.

# Checking for binary logging on master...

# Setting up replication...

# ...done.

建议

在从的my.cnf文件中配置read_only=1来确保数据不被意外修改,只允许从主读取事件。

使用 --pedantic 和 -vv 选项来避免不同的存储引擎可能导致的问题。

权限

在主上需要对mysql数据库具有SELECT 和 INSERT权限,同时还要有REPLICATION SLAVE, REPLICATION CLIENT 和 GRANT OPTION权限。

在从上需要有SUPER 权限。

对于复制用户, --rpl-user 选项使用的,要么自动创建要么指定已经存在的,需要具有 REPLICATION SLAVE 权

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凤舞飘伶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值