MySQL管理工具MySQL Utilities — mysqlreplicate(41)

默北 MySQLMySQL管理工具MySQL Utilities — mysqlreplicate(41)已关闭评论10,200字数 4789阅读15分57秒阅读模式

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

该工具报告条件是当主和从的存储引擎不一样时。如果主和从的存储引擎不同将产生告警信息。对于Innodb存储引擎而言,必需完全一样,Innodb的类型(built-in 或 InnoDB Plugin)需要一样,同时主次版本号也要一样,并启用状态。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

默认情况下,该工具的警告问题在于下面的信息不匹配,存储引擎设置、默认存储引擎和Innodb存储引擎。为了使用错误代替警告,使用 --pedantic 选项来要求主从存储引擎必需一直。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

为了查看存储引擎和innodb值之间的差异,可以使用-vv选项,不管有没使用--pedantic选项。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

可以使用下面的策略启动复制:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

  • 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 选项。

选项

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 权限。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

主和从的server ID必须非零和唯一的。如果为0或相同产生错误报告。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

IP地址和主机名混合使用不推荐。涉及到反向解析的问题。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

MySQL客户端工具的路径需要包含在PATH环境变量中,以便使用login-paths验证机制。允许使用my_print_defaults 来从登陆配置文件(.mylogin.cnf)读取login-path值。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

实例

在同一台服务器上使用相同的默认设置不同端口的两个实例的复制,命令如下:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

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存储引擎。如下所示:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

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.

从当前主的位置开始复制,默认的。如下所示:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

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.

从主记录的事件开始复制,如下所示:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

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.

从特定的主二进制日志开始复制,如下所示:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

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.

从特定的主二进制日志坐标开始复制(指定二进制文件和位置),如下所示:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

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来确保数据不被意外修改,只允许从主读取事件。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

使用 --pedantic 和 -vv 选项来避免不同的存储引擎可能导致的问题。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

权限

在主上需要对mysql数据库具有SELECT 和 INSERT权限,同时还要有REPLICATION SLAVE, REPLICATION CLIENT 和 GRANT OPTION权限。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

在从上需要有SUPER 权限。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

对于复制用户, --rpl-user 选项使用的,要么自动创建要么指定已经存在的,需要具有 REPLICATION SLAVE 权限。文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/ 文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 07/04/2015 01:00:32
  • 转载请务必保留本文链接:https://www.ttlsa.com/mysql/mysql-utilities-mysqlreplicate/