Rechercher dans le manuel MySQL

13.4.2.6 START SLAVE Syntax

  1. START SLAVE [thread_types] [until_option] [connection_options] [channel_option]
  2.  
  3. thread_types:
  4.     [thread_type [, thread_type] ... ]
  5.  
  6. thread_type:
  7.     IO_THREAD | SQL_THREAD
  8.  
  9. until_option:
  10.     UNTIL {   {SQL_BEFORE_GTIDS | SQL_AFTER_GTIDS} = gtid_set
  11.           |   MASTER_LOG_FILE = 'log_name', MASTER_LOG_POS = log_pos
  12.           |   RELAY_LOG_FILE = 'log_name', RELAY_LOG_POS = log_pos
  13.           |   SQL_AFTER_MTS_GAPS  }
  14.  
  15. connection_options:
  16.     [USER='user_name'] [PASSWORD='user_pass'] [DEFAULT_AUTH='plugin_name'] [PLUGIN_DIR='plugin_dir']
  17.  
  18.  
  19. channel_option:
  20.     FOR CHANNEL channel
  21.  
  22. gtid_set:
  23.     uuid_set [, uuid_set] ...
  24.     | ''
  25.  
  26. uuid_set:
  27.  
  28.     hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh
  29.  
  30. h:
  31.     [0-9,A-F]
  32.  
  33.     n[-n]
  34.  
  35.     (n >= 1)

START SLAVE with no thread_type options starts both of the slave threads. The I/O thread reads events from the master server and stores them in the relay log. The SQL thread reads events from the relay log and executes them. START SLAVE requires the REPLICATION_SLAVE_ADMIN or SUPER privilege.

If START SLAVE succeeds in starting the slave threads, it returns without any error. However, even in that case, it might be that the slave threads start and then later stop (for example, because they do not manage to connect to the master or read its binary log, or some other problem). START SLAVE does not warn you about this. You must check the slave's error log for error messages generated by the slave threads, or check that they are running satisfactorily with SHOW SLAVE STATUS.

START SLAVE causes an implicit commit of an ongoing transaction. See Section 13.3.3, “Statements That Cause an Implicit Commit”.

gtid_next must be set to AUTOMATIC before issuing this statement.

The optional FOR CHANNEL channel clause enables you to name which replication channel the statement applies to. Providing a FOR CHANNEL channel clause applies the START SLAVE statement to a specific replication channel. If no clause is named and no extra channels exist, the statement applies to the default channel. If a START SLAVE statement does not have a channel defined when using multiple channels, this statement starts the specified threads for all channels. This statement is disallowed for the group_replication_recovery channel. See Section 17.2.3, “Replication Channels” for more information.

MySQL supports pluggable user-password authentication with START SLAVE with the USER, PASSWORD, DEFAULT_AUTH and PLUGIN_DIR options, as described in the following list:

  • USER: User name. Cannot be set to an empty or null string, or left unset if PASSWORD is used.

  • PASSWORD: Password.

  • DEFAULT_AUTH: Name of plugin; default is MySQL native authentication.

  • PLUGIN_DIR: Location of plugin.

You cannot use the SQL_THREAD option when specifying any of USER, PASSWORD, DEFAULT_AUTH, or PLUGIN_DIR, unless the IO_THREAD option is also provided.

See Section 6.2.17, “Pluggable Authentication”, for more information.

If an insecure connection is used with any these options, the server issues the warning Sending passwords in plain text without SSL/TLS is extremely insecure.

START SLAVE ... UNTIL supports two additional options for use with global transaction identifiers (GTIDs) (see Section 17.1.3, “Replication with Global Transaction Identifiers”). Each of these takes a set of one or more global transaction identifiers gtid_set as an argument (see GTID Sets, for more information).

When no thread_type is specified, START SLAVE UNTIL SQL_BEFORE_GTIDS causes the slave SQL thread to process transactions until it has reached the first transaction whose GTID is listed in the gtid_set. START SLAVE UNTIL SQL_AFTER_GTIDS causes the slave threads to process all transactions until the last transaction in the gtid_set has been processed by both threads. In other words, START SLAVE UNTIL SQL_BEFORE_GTIDS causes the slave SQL thread to process all transactions occurring before the first GTID in the gtid_set is reached, and START SLAVE UNTIL SQL_AFTER_GTIDS causes the slave threads to handle all transactions, including those whose GTIDs are found in gtid_set, until each has encountered a transaction whose GTID is not part of the set. SQL_BEFORE_GTIDS and SQL_AFTER_GTIDS each support the SQL_THREAD and IO_THREAD options, although using IO_THREAD with them currently has no effect.

For example, START SLAVE SQL_THREAD UNTIL SQL_BEFORE_GTIDS = 3E11FA47-71CA-11E1-9E33-C80AA9429562:11-56 causes the slave SQL thread to process all transactions originating from the master whose server_uuid is 3E11FA47-71CA-11E1-9E33-C80AA9429562 until it encounters the transaction having sequence number 11; it then stops without processing this transaction. In other words, all transactions up to and including the transaction with sequence number 10 are processed. Executing START SLAVE SQL_THREAD UNTIL SQL_AFTER_GTIDS = 3E11FA47-71CA-11E1-9E33-C80AA9429562:11-56, on the other hand, would cause the slave SQL thread to obtain all transactions just mentioned from the master, including all of the transactions having the sequence numbers 11 through 56, and then to stop without processing any additional transactions; that is, the transaction having sequence number 56 would be the last transaction fetched by the slave SQL thread.

When using a multithreaded slave with slave_preserve_commit_order=0 set, there is a chance of gaps in the sequence of transactions that have been executed from the relay log in the following cases:

  • killing the coordinator thread

  • after an error occurs in the applier threads

  • mysqld shuts down unexpectedly

Use the START SLAVE UNTIL SQL_AFTER_MTS_GAPS statement to cause a multithreaded slave's worker threads to only run until no more gaps are found in the relay log, and then to stop. This statement can take an SQL_THREAD option, but the effects of the statement remain unchanged. It has no effect on the slave I/O thread (and cannot be used with the IO_THREAD option).

Issuing START SLAVE on a multithreaded slave with gaps in the sequence of transactions executed from the relay log generates a warning. In such a situation, the solution is to use START SLAVE UNTIL SQL_AFTER_MTS_GAPS, then issue RESET SLAVE to remove any remaining relay logs. See Section 17.4.1.33, “Replication and Transaction Inconsistencies” for more information.

To change a failed multithreaded slave to single-threaded mode, you can issue the following series of statements, in the order shown:

  1. START SLAVE UNTIL SQL_AFTER_MTS_GAPS;
  2.  
  3. SET @@GLOBAL.slave_parallel_workers = 0;
  4.  
  5. START SLAVE SQL_THREAD;
Note

It is possible to view the entire text of a running START SLAVE ... statement, including any USER or PASSWORD values used, in the output of SHOW PROCESSLIST. This is also true for the text of a running CHANGE MASTER TO statement, including any values it employs for MASTER_USER or MASTER_PASSWORD.

START SLAVE sends an acknowledgment to the user after both the I/O thread and the SQL thread have started. However, the I/O thread may not yet have connected. For this reason, a successful START SLAVE causes SHOW SLAVE STATUS to show Slave_SQL_Running=Yes, but this does not guarantee that Slave_IO_Running=Yes (because Slave_IO_Running=Yes only if the I/O thread is running and connected). For more information, see Section 13.7.6.34, “SHOW SLAVE STATUS Syntax”, and Section 17.1.7.1, “Checking Replication Status”.

You can add IO_THREAD and SQL_THREAD options to the statement to name which of the threads to start. The SQL_THREAD option is disallowed when specifying any of USER, PASSWORD, DEFAULT_AUTH, or PLUGIN_DIR, unless the IO_THREAD option is also provided.

An UNTIL clause (until_option, in the preceding grammar) may be added to specify that the slave should start and run until the SQL thread reaches a given point in the master binary log, specified by the MASTER_LOG_POS and MASTER_LOG_FILE options, or a given point in the slave relay log, indicated with the RELAY_LOG_POS and RELAY_LOG_FILE options. When the SQL thread reaches the point specified, it stops. If the SQL_THREAD option is specified in the statement, it starts only the SQL thread. Otherwise, it starts both slave threads. If the SQL thread is running, the UNTIL clause is ignored and a warning is issued. You cannot use an UNTIL clause with the IO_THREAD option.

It is also possible with START SLAVE UNTIL to specify a stop point relative to a given GTID or set of GTIDs using one of the options SQL_BEFORE_GTIDS or SQL_AFTER_GTIDS, as explained previously in this section. When using one of these options, you can specify SQL_THREAD, IO_THREAD, both of these, or neither of them. If you specify only SQL_THREAD, then only the slave SQL thread is affected by the statement; if only IO_THREAD is used, then only the slave I/O is affected. If both SQL_THREAD and IO_THREAD are used, or if neither of them is used, then both the SQL and I/O threads are affected by the statement.

For an UNTIL clause, you must specify any one of the following:

  • Both a log file name and a position in that file

  • Either of SQL_BEFORE_GTIDS or SQL_AFTER_GTIDS

  • SQL_AFTER_MTS_GAPS

Do not mix master and relay log options. Do not mix log file options with GTID options.

The UNTIL clause is not supported for multithreaded slaves except when also using SQL_AFTER_MTS_GAPS. If UNTIL is used on a multithreaded slave without SQL_AFTER_MTS_GAPS, the slave operates in single-threaded (sequential) mode for replication until the point specified by the UNTIL clause is reached.

Any UNTIL condition is reset by a subsequent STOP SLAVE statement, a START SLAVE statement that includes no UNTIL clause, or a server restart.

When specifying a log file and position, you can use the IO_THREAD option with START SLAVE ... UNTIL even though only the SQL thread is affected by this statement. The IO_THREAD option is ignored in such cases. The preceding restriction does not apply when using one of the GTID options (SQL_BEFORE_GTIDS and SQL_AFTER_GTIDS); the GTID options support both SQL_THREAD and IO_THREAD, as explained previously in this section.

The UNTIL clause can be useful for debugging replication, or to cause replication to proceed until just before the point where you want to avoid having the slave replicate an event. For example, if an unwise DROP TABLE statement was executed on the master, you can use UNTIL to tell the slave to execute up to that point but no farther. To find what the event is, use mysqlbinlog with the master binary log or slave relay log, or by using a SHOW BINLOG EVENTS statement.

If you are using UNTIL to have the slave process replicated queries in sections, it is recommended that you start the slave with the --skip-slave-start option to prevent the SQL thread from running when the slave server starts. It is probably best to use this option in an option file rather than on the command line, so that an unexpected server restart does not cause it to be forgotten.

The SHOW SLAVE STATUS statement includes output fields that display the current values of the UNTIL condition.

In very old versions of MySQL (before 4.0.5), this statement was called SLAVE START. That syntax now produces an error.


Zoek in de MySQL-handleiding

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-start-slave.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut