<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=MySQL_Replication</id>
	<title>MySQL Replication - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=MySQL_Replication"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=MySQL_Replication&amp;action=history"/>
	<updated>2026-05-13T23:38:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=MySQL_Replication&amp;diff=23489&amp;oldid=prev</id>
		<title>90.152.2.38 at 14:12, 23 October 2014</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=MySQL_Replication&amp;diff=23489&amp;oldid=prev"/>
		<updated>2014-10-23T14:12:11Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Cat|MySQL|050}}&lt;br /&gt;
{{Cat|MariaDB|050}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;slideshow style=&amp;quot;nobleprog&amp;quot; headingmark=&amp;quot;⌘&amp;quot; incmark=&amp;quot;…&amp;quot; scaled=&amp;quot;true&amp;quot; font=&amp;quot;Trebuchet MS&amp;quot; &amp;gt;&lt;br /&gt;
;title: MySQL Replication&lt;br /&gt;
;author: Bernard Szlachta (NobleProg Ltd)&lt;br /&gt;
&amp;lt;/slideshow&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What is Replication? ⌘==&lt;br /&gt;
* Data from Master server are replicated to one or more Slave server&lt;br /&gt;
* Replication is asynchronous - slaves do not need to be connected permanently to receive updates from the master&lt;br /&gt;
* Updates can occur over long-distance connections&lt;br /&gt;
* You can replicate all databases, selected databases, or even selected tables within a database&lt;br /&gt;
&lt;br /&gt;
== Why replication? ⌘==&lt;br /&gt;
* Scale-out solutions&lt;br /&gt;
** all writes and updates must take place on the master&lt;br /&gt;
** reads take place on one or more slaves&lt;br /&gt;
** the master is dedicated to updates, slaves are dedicated for reads&lt;br /&gt;
* Data security&lt;br /&gt;
** to run &amp;quot;backup&amp;quot; services on the slave without corrupting the corresponding master data&lt;br /&gt;
** switch to slave if the master is unavailable or corrupted&lt;br /&gt;
* Analytics, Data Warehouses&lt;br /&gt;
** live data on the master&lt;br /&gt;
** analysis of the information takes place on the slave&lt;br /&gt;
* Long-distance data distribution and security&lt;br /&gt;
** a branch office would like to work with a copy of your main data&lt;br /&gt;
** slave can be used without requiring permanent access to the master&lt;br /&gt;
&lt;br /&gt;
== Synchronous vs. Asynchronous ⌘==&lt;br /&gt;
* MySQL support for one-way, asynchronous replication (master -&amp;gt; slave(s))&lt;br /&gt;
* The synchronous replication is implemented by Gallera Cluster (master &amp;lt;-&amp;gt; master)&lt;br /&gt;
&lt;br /&gt;
== MariaDB Parallel Replication ==&lt;br /&gt;
https://mariadb.com/kb/en/mariadb/documentation/replication/standard-replication/parallel-replication/&lt;br /&gt;
&lt;br /&gt;
== Types of Replication ==&lt;br /&gt;
* Statement Based Replication (SBR)&lt;br /&gt;
** replicates entire SQL statements&lt;br /&gt;
* Row Based Replication (RBR)&lt;br /&gt;
** replicates only the changed rows&lt;br /&gt;
* Mixed Based Replication (MBR)&lt;br /&gt;
** the default mode within MySQL 5.1.12 and later&lt;br /&gt;
&lt;br /&gt;
== How Replication Works (part 1)? ⌘==&lt;br /&gt;
* Replication uses binary logging mechanism&lt;br /&gt;
* The master writes updates and changes as “events” to the binary log&lt;br /&gt;
* Slaves are configured to read the binary log from the master and to execute the events in the binary log on the slave&amp;#039;s local database&lt;br /&gt;
* The master is “dumb” in this scenario (knows nothing about slaves)&lt;br /&gt;
* Each slave will receive a copy of the entire contents of the binary log&lt;br /&gt;
&lt;br /&gt;
== How Replication Works (part 2)? ⌘==&lt;br /&gt;
* It is the responsibility of the slave to decide which statements in the binary log should be executed&lt;br /&gt;
* You cannot configure the master to log only certain events&lt;br /&gt;
* If you do not specify otherwise, all events in the master binary log are executed on the slave&lt;br /&gt;
* If required, you can configure the slave to process only events that apply to particular databases or tables.&lt;br /&gt;
* Each slave keeps a record of the binary log file and position within the log file that it has read and processed from the master (relay)&lt;br /&gt;
* This means that multiple slaves can be connected to the master and executing different parts of the same binary log&lt;br /&gt;
&lt;br /&gt;
== How Replication Works (part 3)? ⌘==&lt;br /&gt;
* Because the slaves control this process, individual slaves can be connected and disconnected from the server without affecting the master&amp;#039;s operation&lt;br /&gt;
* Slaves can be disconnected, reconnect and then “catch up” by continuing from the recorded position.&lt;br /&gt;
* The master and each slave must have a unique ID (server-id)&lt;br /&gt;
* The slave must know the master host name, log file name and position within that file&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;CHANGE MASTER TO&amp;#039;&amp;#039;&amp;#039; statement sets &lt;br /&gt;
** the address of the master&lt;br /&gt;
** binary log file name&lt;br /&gt;
** position in the binary log&lt;br /&gt;
* CHANGE MASTER TO statement stores the data in the &amp;#039;&amp;#039;&amp;#039;master.info&amp;#039;&amp;#039;&amp;#039; file&lt;br /&gt;
&lt;br /&gt;
== How to Set Up Replication (from new database) ⌘==&lt;br /&gt;
# Create a separate user that will be used by your slaves to Authenticate with the master to read the binary log for replication (optional)&lt;br /&gt;
# Configure the master to support the binary log and configure a unique ID (required)&lt;br /&gt;
# Configure a unique ID for each slave (required)&lt;br /&gt;
# Configure the slave with the master settings, such as the host name, login credentials and binary log name and positions&lt;br /&gt;
# Start replication&lt;br /&gt;
&lt;br /&gt;
== 1. Creating a User for Replication ⌘==&lt;br /&gt;
* Each slave must connect to the master using a standard MySQL user name and password&lt;br /&gt;
* Any account can be used for this operation, providing it has been granted the REPLICATION SLAVE privilege&lt;br /&gt;
* You do not need to create a specific user for replication. you should be aware that the user name and password will be stored in plain text within the master.info file&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
 GRANT REPLICATION SLAVE ON *.* TO &amp;#039;repl&amp;#039;@&amp;#039;%.mydomain.com&amp;#039; IDENTIFIED BY &amp;#039;slavepass&amp;#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 2. Setting Master Configuration ⌘==&lt;br /&gt;
* You must enable binary logging on the master&lt;br /&gt;
* Each server within a replication group must be configured with a unique server-id value&lt;br /&gt;
* The server ID is used to identify individual servers within the group, and must be between 1 and 231&lt;br /&gt;
* Edit my.cnf or my.ini file&lt;br /&gt;
* Add the lines below&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 log-bin=mysql-bin&lt;br /&gt;
 server-id=1&lt;br /&gt;
&lt;br /&gt;
== 3. Setting Slave Configuration ==&lt;br /&gt;
* You must set the unique server ID&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 server-id=2&lt;br /&gt;
* If you do not specify a server-id value, it defaults to 0.&lt;br /&gt;
* If you omit server-id (or set it explicitly to 0), a master refuses connections from all slaves, and a slave refuses to connect to a master. &lt;br /&gt;
* Omitting server-id is good only for backup with a binary log.&lt;br /&gt;
* You do NOT have to enable binary logging on the slave for replication to be enabled&lt;br /&gt;
&lt;br /&gt;
== 4a. Obtaining Master Information ==&lt;br /&gt;
* You must determine the master&amp;#039;s current point within the master binary log&lt;br /&gt;
* Execute FLUSH TABLES WITH READ LOCK; on the master server and leave the session open&lt;br /&gt;
* Use the SHOW MASTER STATUS on the master server to get&lt;br /&gt;
** Binary Log Position&lt;br /&gt;
** Binary Log Filename&lt;br /&gt;
* You now have the information you need to enable the slave to start reading from the binary log in the correct place to start replication.&lt;br /&gt;
&lt;br /&gt;
== 4b. Configure slave with master settings ==&lt;br /&gt;
* On the master, release the read lock:&lt;br /&gt;
** UNLOCK TABLES;&lt;br /&gt;
* Start up the MySQL slave&lt;br /&gt;
* Execute the CHANGE MASTER TO &lt;br /&gt;
 CHANGE MASTER TO&lt;br /&gt;
    MASTER_HOST=&amp;#039;localhost&amp;#039;,&lt;br /&gt;
    MASTER_USER=&amp;#039;rep&amp;#039;,&lt;br /&gt;
    MASTER_PASSWORD=&amp;#039;asdf&amp;#039;,&lt;br /&gt;
    MASTER_LOG_FILE=&amp;#039;mysql-bin.000001&amp;#039;,&lt;br /&gt;
    MASTER_LOG_POS=106;&lt;br /&gt;
&lt;br /&gt;
== 5. Start Replication ==&lt;br /&gt;
* START SLAVE starts both of the slave threads. &lt;br /&gt;
** The I/O thread reads queries from the master server and stores them in the relay log.&lt;br /&gt;
** The SQL thread reads the relay log and executes the queries&lt;br /&gt;
* START SLAVE requires the SUPER privilege&lt;br /&gt;
* Slave threads can start and then later stop&lt;br /&gt;
** for example they do not manage to connect to the master or read its binary logs&lt;br /&gt;
** START SLAVE does not warn you about this&lt;br /&gt;
** You must check the slave&amp;#039;s error log for error messages generated by the slave threads&lt;br /&gt;
** SHOW SLAVE STATUS shows whether replication is working&lt;/div&gt;</summary>
		<author><name>90.152.2.38</name></author>
	</entry>
</feed>