Description\n-----------\n\nThe CHANGE MASTER TO statement sets up a replication slave server to connect to a specific master server and defines the replication coordinates (binary log file and position or GTID) and connection parameters (host, user, password, port, SSL options, etc.). When executed, the slave updates its internal replication metadata accordingly.\n\nSyntax\n\n``sql\nCHANGE MASTER ['connection_name'] TO master_def  [, master_def] ... \n  [FOR CHANNEL 'channel_name']\n\nmaster_def:\n    MASTER_BIND = 'interface_name'\n  | MASTER_HOST = 'host_name'\n  | MASTER_USER = 'user_name'\n  | MASTER_PASSWORD = 'password'\n  | MASTER_PORT = port_num\n  | MASTER_CONNECT_RETRY = {interval | DEFAULT}\n  | MASTER_HEARTBEAT_PERIOD = {interval | DEFAULT}\n  | MASTER_LOG_FILE = 'master_log_name'\n  | MASTER_LOG_POS = master_log_pos\n  | RELAY_LOG_FILE = 'relay_log_name'\n  | RELAY_LOG_POS = relay_log_pos\n  | MASTER_DELAY = interval\n  | MASTER_SSL = {0 | 1 | DEFAULT}\n  | MASTER_SSL_CA = {'ca_file_name' | DEFAULT}\n  | MASTER_SSL_CAPATH = {'ca_directory_name' | DEFAULT}\n  | MASTER_SSL_CERT = {'cert_file_name' | DEFAULT}\n  | MASTER_SSL_CRL = {'crl_file_name' | DEFAULT}\n  | MASTER_SSL_CRLPATH = {'crl_directory_name' | DEFAULT}\n  | MASTER_SSL_KEY = {'key_file_name' | DEFAULT}\n  | MASTER_SSL_CIPHER = {'cipher_list' | DEFAULT}\n  | MASTER_SSL_VERIFY_SERVER_CERT = {0 | 1 | DEFAULT}\n  | MASTER_USE_GTID = {current_pos | slave_pos | no | DEFAULT}\n  | MASTER_DEMOTE_TO_SLAVE = bool\n  | IGNORE_SERVER_IDS = (server_id_list)\n  | DO_DOMAIN_IDS = ([N,..])\n  | IGNORE_DOMAIN_IDS = ([N,..])\n  | MASTER_RETRY_COUNT = {long | DEFAULT}\n`\n\nNote: The value is extracted from the corresponding server option or system variable that support DEFAULT. This allows you to reset a replication configuration parameter to its server-level configuration without providing an explicit value.\n\nReplication Configuration\n\nCHANGE MASTER is used on a slave to set up or change replication settings for connecting to the master.\n\nThe FOR CHANNEL keyword was added for MySQL compatibility. This is identical to using the channel_name directly after CHANGE MASTER.\n\nFOR CHANNEL is not available.\n\nMulti-Source Replication\n\nIf you are using multi-source replication, then you need to specify a connection name when you execute CHANGE MASTER. There are two ways to do this:\n\n Setting the default_master_connection system variable prior to executing CHANGE MASTER.\n Setting the connection_name parameter when executing CHANGE MASTER.\n\ndefault_master_connection\n\n`sql\nSET default_master_connection = 'gandalf';\nSTOP SLAVE;\nCHANGE MASTER TO \n   MASTER_PASSWORD='new3cret';\nSTART SLAVE;\n`\n\nconnection_name\n\n`sql\nSTOP SLAVE 'gandalf';\nCHANGE MASTER 'gandalf' TO \n   MASTER_PASSWORD='new3cret';\nSTART SLAVE 'gandalf';\n`\n\nOptions\n\nUsing Configurable Defaults\n\nStarting with MariaDB 12.3, replication connection parameters can be set at the server level (for example, in configuration files like my.cnf or via command-line options) and reused across replication channels.\n\nWhen an option in CHANGE MASTER TO is set to DEFAULT, the value is obtained from the corresponding server option (e.g., options defined in configuration files like my.cnf or provided on the command line). Instead of keeping a fixed value, the replication channel derives the value from the appropriate server option when DEFAULT is selected.\n\n<table><thead><tr><th width="224">CHANGE MASTER Option</th><th width="230">System Variable</th><th>Description</th></tr></thead><tbody><tr><td><code>MASTER_CONNECT_RETRY</code></td><td><code>--master-connect-retry</code></td><td>The interval to wait between connection retry attempts.</td></tr><tr><td><code>MASTER_RETRY_COUNT</code></td><td><code>--master-retry-count</code></td><td>Number of connection attempts before stopping.</td></tr><tr><td><code>MASTER_HEARTBEAT_PERIOD</code></td><td><code>--master-heartbeat-period</code></td><td>Interval between replication heartbeats.</td></tr><tr><td><code>MASTER_SSL</code></td><td><code>--master-ssl</code></td><td>Enables or disables TLS for the connection.</td></tr><tr><td><code>MASTER_SSL_CA</code></td><td><code>--master-ssl-ca</code></td><td>Path to the Certificate Authority (CA) file.</td></tr><tr><td><code>MASTER_SSL_CERT</code></td><td><code>--master-ssl-cert</code></td><td>Path to the client certificate file.</td></tr><tr><td><code>MASTER_SSL_KEY</code></td><td><code>--master-ssl-key</code></td><td>Path to the client private key file.</td></tr><tr><td><code>MASTER_SSL_CAPATH</code></td><td><code>--master-ssl-capath</code></td><td>Path to the directory containing CA certificates.</td></tr><tr><td><code>MASTER_SSL_VERIFY_SERVER_CERT</code></td><td><code>--master-ssl-verify-server-cert</code></td><td>Enable verification of the master's certificate.</td></tr><tr><td><code>MASTER_SSL_CRL</code></td><td><code>--master-ssl-crl</code></td><td>Path to the Certificate Revocation List (CRL) file.</td></tr><tr><td><code>MASTER_SSL_CRLPATH</code></td><td><code>--master-ssl-crlpath</code></td><td>Path to the directory containing CRL files.</td></tr><tr><td><code>MASTER_SSL_CIPHER</code></td><td><code>--master-ssl-cipher</code></td><td>List of permitted TLS ciphers.</td></tr><tr><td><code>MASTER_USE_GTID</code></td><td><code>--master-use-gtid</code></td><td>Setting for Global Transaction ID (GTID) mode.</td></tr></tbody></table>\n\nFor example, a configuration file can specify default values:\n\n`\nDefaults replication connection options\nmaster_ssl_ca   = /etc/mysql/ssl/ca.pem\nmaster_ssl_cert = /etc/mysql/ssl/client-cert.pem\nmaster_ssl_key  = /etc/mysql/ssl/client-key.pem\nmaster_use_gtid = slave_pos\n`\n\nThese values can then be reused by specifying DEFAULT:\n\n`\n-- Setting up a specific channel using global defaults\nCHANGE MASTER 'primary_node_1' TO\n  MASTER_HOST = '10.0.0.5',\n  MASTER_SSL_CA = DEFAULT,\n  MASTER_SSL_CERT = DEFAULT,\n  MASTER_SSL_KEY = DEFAULT,\n  MASTER_USE_GTID = DEFAULT;\n\nSTART SLAVE 'primary_node_1';\n`\n\nIf an option is explicitly set in CHANGE MASTER TO, the value overrides the corresponding server option. The replication channel receives the current server-level value if DEFAULT is used.\n\nValues set to DEFAULT are fixed dynamically, thus changes to server options (for example, after a restart) are automatically reflected, whereas explicitly defined values remain unchanged.\n\nBehavior and Persistence\n\nWhen DEFAULT is used, the option is stored in the replication metadata as DEFAULT instead of a specific value. The new value will be used automatically if the corresponding server option changes (for instance, after a server restart).\n\nChanges to server settings have no effect on an explicit value that is provided instead of DEFAULT. When a CHANGE MASTER option is not explicitly set, it acts as DEFAULT.\n\nConfiguration Precedence\n\nValues explicitly defined in CHANGE MASTER TO take precedence over server settings.\n\nThe replication channel can inherit values from server-level configuration rather than overriding them when the DEFAULT keyword is used.\n\nAutoset Options\n\nThe following options can override manual defaults:\n\n --autoset-master-heartbeat-period\n --autoset-master-use-gtid\n\nThese options determine values automatically and may override --master- settings.\n\nConnection Options\n\nMASTER_USER\n\nThe MASTER_USER option for CHANGE MASTER defines the user account that the slave will use to connect to the master.\n\nThis user account will need the REPLICATION SLAVE privilege on the master.\n\nThis user account will need the REPLICATION SLAVE privilege on the master.\n\nFor example:\n\n`sql\nSTOP SLAVE;\nCHANGE MASTER TO\n   MASTER_USER='repl',\n   MASTER_PASSWORD='new3cret';\nSTART SLAVE;\n`\n\nThe maximum length of the MASTER_USER string is 128 characters.\n\nThe maximum length of the MASTER_USER string is 96 characters.\n\nMASTER_PASSWORD\n\nThe MASTER_PASSWORD option for CHANGE MASTER defines the password that the slave will use to connect to the master as the user account defined by the MASTER_USER option.\n\nFor example:\n\n`sql\nSTOP SLAVE;\nCHANGE MASTER TO \n   MASTER_PASSWORD='new3cret';\nSTART SLAVE;\n`\n\nThe maximum length of the MASTER_PASSWORD string is 32 characters. The effective maximum length of the string depends on how many bytes are used per character and can be up to 96 characters.\n\nDue to MDEV-29994, the password can be silently truncated to 41 characters when MariaDB is restarted. For this reason, it is recommended to use a password that is shorter than this.\n\nMASTER_HOST\n\nThe MASTER_HOST option for CHANGE MASTER defines the hostname or IP address of the master.\n\nIf you set the value of the MASTER_HOST option to the empty string, then that is not the same as not setting the option's value at all. If you set the value of the MASTER_HOST option to the empty string, then the CHANGE MASTER command will fail with an error.\n\nIf you set the value of the MASTER_HOST option to the empty string, then that is not the same as not setting the option's value at all. If you set the value of the MASTER_HOST option to the empty string, then the CHANGE MASTER command will fail with an error. In MariaDB 5.3 and before, if you set the value of the MASTER_HOST option to the empty string, then the CHANGE MASTER command would succeed, but the subsequent START SLAVE command would fail.\n\nFor example:\n\n`sql\nSTOP SLAVE;\nCHANGE MASTER TO\n   MASTER_HOST='dbserver1.example.com',\n   MASTER_USER='repl',\n   MASTER_PASSWORD='new3cret',\n   MASTER_USE_GTID=slave_pos;\nSTART SLAVE;\n`\n\nIf you set the value of the MASTER_HOST option in a CHANGE MASTER command, then the slave assumes that the master is different from before, even if you set the value of this option to the same value it had previously. In this scenario, the slave will consider the old values for the master's binarylog file name and position to be invalid for the new master. As a side effect, if you do not explicitly set the values of the MASTER_LOG_FILE and MASTER_LOG_POS options in the statement, then the statement will be implicitly appended with MASTER_LOG_FILE='' and MASTER_LOG_POS=4. However, if you enable GTID mode for replication by setting the MASTER_USE_GTID option to some value other than no in the statement, then these values will effectively be ignored anyway.\n\nSlaves cannot connect to primaries using Unix socket files or Windows named pipes. The slave must connect to the master using TCP/IP.\n\nThe maximum length of the MASTER_HOST string is 255 characters.\n\nThe maximum length of the MASTER_HOST string is 60 characters.\n\nMASTER_PORT\n\nThe MASTER_PORT option for CHANGE MASTER defines the TCP/IP port of the master.\n\nFor example:\n\n`sql\nSTOP SLAVE;\nCHANGE MASTER TO\n   MASTER_HOST='dbserver1.example.com',\n   MASTER_PORT=3307,\n   MASTER_USER='repl',\n   MASTER_PASSWORD='new3cret',\n   MASTER_USE_GTID=slave_pos;\nSTART SLAVE;\n`\n\nIf you set the value of the MASTER_PORT option in a CHANGE MASTER command, then the slave assumes that the master is different from before, even if you set the value of this option to the same value it had previously. In this scenario, the slave will consider the old values for the master's binary log file name and position to be invalid for the new master. As a side effect, if you do not explicitly set the values of the MASTER_LOG_FILE and MASTER_LOG_POS options in the statement, then the statement will be implicitly appended with MASTER_LOG_FILE='' and MASTER_LOG_POS=4. However, if you enable GTID mode for replication by setting the MASTER_USE_GTID option to some value other than no in the statement, then these values will effectively be ignored anyway.\n\nSlaves cannot connect to primaries using Unix socket files or Windows named pipes. The slave must connect to the master using TCP/IP.\n\nMASTER_CONNECT_RETRY\n\nThe MASTER_CONNECT_RETRY option for CHANGE MASTER defines how many seconds that the slave will wait between connection retries. The default is 60.\n\n`sql\nSTOP SLAVE;\nCHANGE MASTER TO \n   MASTER_CONNECT_RETRY=20;\nSTART SLAVE;\n`\n\n> Starting with MariaDB 12.3, this option accepts the DEFAULT keyword. When set to DEFAULT, the value is taken from the corresponding server option (for example, --master-connect-retry defined in the configuration files or on the command line).\\\n> \\\n> The option can now be set to 0, which disables the wait between connection retries.\n\nMASTER_RETRY_COUNT\n\nThe MASTER_RETRY_COUNT option limits the number of connection attempts (i.e., Connects_Tried in SHOW SLAVE STATUS). For example:\n\n`sql\nSTOP SLAVE;\nCHANGE MASTER TO\n  MASTER_RETRY_COUNT=1; # attempt only once; do not retry if it fails\nSTART SLAVE;\n`\n\nSetting this option resets the Connects_Tried statistic in SHOW SLAVE STATUS to 0.\n\nThe default is the --master-retry-count option, which can be set either on the command-line or in a server option group in an option file prior to starting up the server. For example:\n\nThe MASTER_RETRY_COUNT option for CHANGE MASTER is only supported by MariaDB 12.0.1 and later and by MySQL. Please use the --master-retry-count option instead, which be set either on the command-line or in a server option group in an option file prior to starting up the server. For example:\n\n`ini\n[mariadb]\n...\nmaster_retry_count=4294967295\n`\n\nThe maximum value is 18446744073709551615 (64-bit). Before MariaDB 12.3, the maximum value for Windows was 4294967295.\n\n> Starting with MariaDB 12.3, this option accepts the DEFAULT keyword. When set to DEFAULT, the value is taken from the corresponding server option (for example, --master-retry-count).\n>\n> The option can now be set to 0, allowing the slave to retry indefinitely.\n> \\\n> When it is set to 1, the connection attempt is only made once, hence disabling retries.\n\nMASTER_BIND\n\nThe MASTER_BIND option for CHANGE MASTER is only supported by MySQL 5.6.2 and later and by MySQL NDB Cluster 7.3.1 and later. This option is not supported by MariaDB. See MDEV-19248 for more information.\n\nThe MASTER_BIND option for CHANGE MASTER can be used on slaves that have multiple network interfaces to choose which network interface the slave will use to connect to the master.\n\nMASTER_HEARTBEAT_PERIOD\n\nThe MASTER_HEARTBEAT_PERIOD option for CHANGE MASTER can be used to set 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.\n\nThis option's _interval_ argument has the following characteristics:\n\n It is a decimal value with a range of 0 to 4294967.295 seconds.\n It has a resolution of hundredths of a second.\n Its smallest valid non-zero value is 0.001.\n Its default value is the value of the slave_net_timeout system variable divided by 2.\n If it's set to 0, then heartbeats are disabled.\n\nHeartbeats are sent by the master only if there are no unsent events in the binary log file for a period longer than the interval.\n\n> Starting with MariaDB 12.3, this option accepts the DEFAULT keyword. When set to DEFAULT, the value is taken from the corresponding server opti\n\n[Truncated — full content at mariadb.com/docs]