mysqlreplicate

mysqlreplicate 建立主备复制关系

$ ./mysqlreplicate --help
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
  --master=MASTER       connection information for master server in the form:
                        <user>[:<password>]@<host>[:<port>][:<socket>] or
                        <login-path>[:<port>][:<socket>].
  --slave=SLAVE         connection information for slave server in the form:
                        <user>[:<password>]@<host>[:<port>][:<socket>] or
                        <login-path>[:<port>][:<socket>].
  --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 - By default = rpl:rpl
  -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.
  -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.
  -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.

eg1:master和slave,因为没有对master进行锁的操作,所以数据可能不一致

$ ./mysqlreplicate --master=root@localhost:3306 --slave=root@localhost:3406 --rpl-user=slave:slave -vv
# master on localhost: ... connected.
# slave on localhost: ... connected.
# master id = 15444555
#  slave id = 15444556
# master uuid = None
#  slave uuid = None
# Checking InnoDB statistics for type and version conflicts.
# Checking storage engines...
# Checking for binary logging on master...
# Setting up replication...
# Connecting slave to master...
# CHANGE MASTER TO MASTER_HOST = 'localhost', MASTER_USER = 'slave', MASTER_PASSWORD = 'slave', MASTER_PORT = 3306, MASTER_LOG_FILE = 'mysql-bin.002592', MASTER_LOG_POS = 296485727
# Starting slave from master's last position...
# status: Waiting for master to send event
# error: 0:
# ...done.

master:

root@luoxuan 03:09:59>select COUNT(*) FROM test;
+----------+
| COUNT(*) |
+----------+
|   149517 |
+----------+

slave:

root@luoxuan 03:10:25>select COUNT(*) FROM test;
+----------+
| COUNT(*) |
+----------+
|   136772 |
+----------+

eg2:加pedantic来确保主备存储引擎相同

$ ./mysqlreplicate --master=root@localhost:3306 --slave=root@localhost:3406 --rpl-user=slave:slave --pedantic -vv
# master on localhost: ... connected.
# slave on localhost: ... connected.
# master id = 15444555
#  slave id = 15444556
# master uuid = None
#  slave uuid = None
# Checking InnoDB statistics for type and version conflicts.
# Checking storage engines...
# Checking for binary logging on master...
# Setting up replication...
# Connecting slave to master...
# CHANGE MASTER TO MASTER_HOST = 'localhost', MASTER_USER = 'slave', MASTER_PASSWORD = 'slave', MASTER_PORT = 3306, MASTER_LOG_FILE = 'mysql-bin.002592', MASTER_LOG_POS = 360024453
# Starting slave from master's last position...
# status: Waiting for master to send event
# error: 0:
# ...done.

注意:看文档上会FTWRL,但实际版本(percona 5.5.18)并未FTWRL,导致数据不一致。可能mysql工具是基于oracle的mysql版本做的测试?


Post a Comment