CHANGE MASTER TO
Syntax
CHANGE MASTER TO
changes the parameters that the slave server uses for connecting to the master server, for reading the master binary log, and reading the slave relay log. It also updates the contents of the master.info
and relay-log.info
files. To use CHANGE MASTER TO
, the slave replication threads must be stopped (use STOP SLAVE
if necessary).
Options not specified retain their value, except as indicated in the following discussion. Thus, in most cases, there is no need to specify options that do not change. For example, if the password to connect to your MariaDB master has changed, you just need to issue these statements to tell the slave about the new password:
STOP SLAVE; -- if replication was running CHANGE MASTER TO MASTER_PASSWORD='new3cret'; START SLAVE; -- if you want to restart replication
MASTER_HOST
, MASTER_USER
, MASTER_PASSWORD
, and MASTER_PORT
provide information to the slave about how to connect to its master:
MASTER_HOST
andMASTER_PORT
are the host name (or IP address) of the master host and its TCP/IP port.NoteReplication cannot use Unix socket files. You must be able to connect to the master MariaDB server using TCP/IP.
If you specify the
MASTER_HOST
orMASTER_PORT
option, the slave assumes that the master server is different from before (even if the option value is the same as its current value.) In this case, the old values for the master binary log file name and position are considered no longer applicable, so if you do not specifyMASTER_LOG_FILE
andMASTER_LOG_POS
in the statement,MASTER_LOG_FILE=''
andMASTER_LOG_POS=4
are silently appended to it.Setting
MASTER_HOST=''
(that is, setting its value explicitly to an empty string) is not the same as not settingMASTER_HOST
at all. Beginning with MariaDB 5.5, trying to setMASTER_HOST
to an empty string fails with an error. Previously, settingMASTER_HOST
to an empty string causedSTART SLAVE
subsequently to fail. (Bug #28796)In MariaDB 5.6.5 and later, values used for
MASTER_HOST
and otherCHANGE MASTER TO
options are checked for linefeed (\n
or0x0A
) characters; the presence of such characters in these values causes the statement to fail with ER_MASTER_INFO. (Bug #11758581, Bug #50801)MASTER_USER
andMASTER_PASSWORD
are the user name and password of the account to use for connecting to the master.In MariaDB 5.6.4 and later,
MASTER_USER
cannot be made empty; settingMASTER_USER = ''
or leaving it unset when setting a value for forMASTER_PASSWORD
causes an error (Bug #13427949).Currently, a password used for a replication slave account can exceed 32 characters, but any characters in excess of this number are truncated. This is not due to any limit imposed by the MariaDB Server but rather one that is specific to MariaDB Replication. (See Bug #43439, for more information.)
The text of a running
CHANGE MASTER TO
statement, including values forMASTER_USER
andMASTER_PASSWORD
, can be seen in the output of a concurrentSHOW PROCESSLIST
statement. (The complete text of aSTART SLAVE
statement is also visible toSHOW PROCESSLIST
.)
The MASTER_SSL_
options provide information about using SSL for the connection. They correspond to the xxx
--ssl-
options described in , "SSL Command Options", and , "Setting Up Replication Using SSL". These options can be changed even on slaves that are compiled without SSL support. They are saved to the xxx
master.info
file, but are ignored if the slave does not have SSL support enabled. MASTER_SSL_CRL
and MASTER_SSL_CRLPATH
were added in MariaDB 5.6.3.
MASTER_CONNECT_RETRY
specifies how many seconds to wait between connect retries. The default is 60.
MASTER_RETRY_COUNT
, added in MariaDB 5.6.1, limits the number of reconnection attempts and updates the value of the Master_Retry_Count
column in the output of SHOW SLAVE STATUS
(also added in MariaDB 5.6.1). The default value is 24 * 3600 = 86400. MASTER_RETRY_COUNT
is intended to replace the older --master-retry-count
server option, and is now the preferred method for setting this limit. You are encouraged not to rely on --master-retry-count
in new applications and, when upgrading to MariaDB 5.6.1 or later from earlier versions of MySQL, to update any existing applications that rely on it, so that they use CHANGE MASTER TO ... MASTER_RETRY_COUNT
instead.
MASTER_DELAY
specifies how many seconds behind the master the slave must lag. An event received from the master is not executed until at least interval
seconds later than its execution on the master. The default is 0. An error occurs if interval
is not a nonnegative integer in the range from 0 to 231-1. For more information, see , "Delayed Replication". This option was added in MariaDB 5.6.0.
MASTER_BIND
is for use on replication slaves having multiple network interfaces, and determines which of the slave's network interfaces is chosen for connecting to the master.
The address configured with this option, if any, can be seen in the Master_Bind
column of the output from SHOW SLAVE STATUS
. If you are using slave status log tables (server started with --master-info-repository=TABLE
), the value can also be seen as the Master_bind
column of the mysql.slave_master_info
table.
The ability to bind a replication slave to a specific network interface was added in MariaDB 5.6.2.
MASTER_HEARTBEAT_PERIOD
sets the interval in seconds between replication heartbeats. Whenever the master's binary log is updated with an event, the waiting period for the next heartbeat is reset. interval
is a decimal value having the range 0 to 4294967 seconds and a resolution in milliseconds; the smallest nonzero value is 0.001. Heartbeats are sent by the master only if there are no unsent events in the binary log file for a period longer than interval
.
If you are logging master connection information to tables, MASTER_HEARTBEAT_PERIOD
can be seen as the value of the Heartbeat
column of the mysql.slave_master_info
table.
Setting interval
to 0 disables heartbeats altogether. The default value for interval
is equal to the value of slave_net_timeout
divided by 2.
Setting @@global.slave_net_timeout
to a value less than that of the current heartbeat interval results in a warning being issued. The effect of issuing RESET SLAVE
on the heartbeat interval is to reset it to the default value.
MASTER_LOG_FILE
and MASTER_LOG_POS
are the coordinates at which the slave I/O thread should begin reading from the master the next time the thread starts. RELAY_LOG_FILE
and RELAY_LOG_POS
are the coordinates at which the slave SQL thread should begin reading from the relay log the next time the thread starts. If you specify either of MASTER_LOG_FILE
or MASTER_LOG_POS
, you cannot specify RELAY_LOG_FILE
or RELAY_LOG_POS
. If neither of MASTER_LOG_FILE
or MASTER_LOG_POS
is specified, the slave uses the last coordinates of the slave SQL thread before CHANGE MASTER TO
was issued. This ensures that there is no discontinuity in replication, even if the slave SQL thread was late compared to the slave I/O thread, when you merely want to change, say, the password to use.
CHANGE MASTER TO
deletes all relay log files and starts a new one, unless you specify RELAY_LOG_FILE
or RELAY_LOG_POS
. In that case, relay log files are kept; the relay_log_purge
global variable is set silently to 0.
Prior to MariaDB 5.6.2, RELAY_LOG_FILE
required an absolute path. Beginning with MariaDB 5.6.2, the path can be relative, and uses the same basename as MASTER_LOG_FILE
. (Bug #12190)
IGNORE_SERVER_IDS
takes a comma-separated list of 0 or more server IDs. Events originating from the corresponding servers are ignored, with the exception of log rotation and deletion events, which are still recorded in the relay log.
In circular replication, the originating server normally acts as the terminator of its own events, so that they are not applied more than once. Thus, this option is useful in circular replication when one of the servers in the circle is removed. Suppose that you have a circular replication setup with 4 servers, having server IDs 1, 2, 3, and 4, and server 3 fails. When bridging the gap by starting replication from server 2 to server 4, you can include IGNORE_SERVER_IDS = (3)
in the CHANGE MASTER TO
statement that you issue on server 4 to tell it to use server 2 as its master instead of server 3. Doing so causes it to ignore and not to propagate any statements that originated with the server that is no longer in use.
If a CHANGE MASTER TO
statement is issued without any IGNORE_SERVER_IDS
option, any existing list is preserved; RESET SLAVE
also has no effect on the server ID list. To clear the list of ignored servers, it is necessary to use the option with an empty list:
CHANGE MASTER TO IGNORE_SERVER_IDS = ();
If IGNORE_SERVER_IDS
contains the server's own ID and the server was started with the --replicate-same-server-id
option enabled, an error results.
In MariaDB 5.6, the master.info
file and the output of SHOW SLAVE STATUS
provide the list of servers that are currently ignored. For more information, see , "Slave Status Logs", and , "SHOW SLAVE STATUS
Syntax".
In MariaDB 5.6, invoking CHANGE MASTER TO
causes the previous values for MASTER_HOST
, MASTER_PORT
, MASTER_LOG_FILE
, and MASTER_LOG_POS
to be written to the error log, along with other information about the slave's state prior to execution.
CHANGE MASTER TO
is useful for setting up a slave when you have the snapshot of the master and have recorded the master binary log coordinates corresponding to the time of the snapshot. After loading the snapshot into the slave to synchronize it to the slave, you can run CHANGE MASTER TO MASTER_LOG_FILE='
on the slave to specify the coordinates at which the slave should begin reading the master binary log.
log_name
', MASTER_LOG_POS=log_pos
The following example changes the master server the slave uses and establishes the master binary log coordinates from which the slave begins reading. This is used when you want to set up the slave to replicate the master:
CHANGE MASTER TO MASTER_HOST='master2.mycompany.com', MASTER_USER='replication', MASTER_PASSWORD='bigs3cret', MASTER_PORT=3306, MASTER_LOG_FILE='master2-bin.001', MASTER_LOG_POS=4, MASTER_CONNECT_RETRY=10;
The next example shows an operation that is less frequently employed. It is used when the slave has relay log files that you want it to execute again for some reason. To do this, the master need not be reachable. You need only use CHANGE MASTER TO
and start the SQL thread (START SLAVE SQL_THREAD
):
CHANGE MASTER TO RELAY_LOG_FILE='slave-relay-bin.006', RELAY_LOG_POS=4025;
You can even use the second operation in a nonreplication setup with a standalone, nonslave server for recovery following a crash. Suppose that your server has crashed and you have restored it from a backup. You want to replay the server's own binary log files (not relay log files, but regular binary log files), named (for example) myhost-bin.*
. First, make a backup copy of these binary log files in some safe place, in case you don't exactly follow the procedure below and accidentally have the server purge the binary log. Use SET GLOBAL relay_log_purge=0
for additional safety. Then start the server without the --log-bin
option, Instead, use the --replicate-same-server-id
, --relay-log=myhost-bin
(to make the server believe that these regular binary log files are relay log files) and --skip-slave-start
options. After the server starts, issue these statements:
CHANGE MASTER TO RELAY_LOG_FILE='myhost-bin.153', RELAY_LOG_POS=410, MASTER_HOST='some_dummy_string'; START SLAVE SQL_THREAD;
The server reads and executes its own binary log files, thus achieving crash recovery. Once the recovery is finished, run STOP SLAVE
, shut down the server, delete the master.info
and relay-log.info
files, and restart the server with its original options.
Specifying the MASTER_HOST
option (even with a dummy value) is required to make the server think it is a slave.
The following table shows the maximum permissible length for the string-valued options.