<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Replication Archives - ServerStadium</title>
	<atom:link href="https://serverstadium.com/knowledge-base/tag/mysql-replication/feed/" rel="self" type="application/rss+xml" />
	<link>https://serverstadium.com/knowledge-base/tag/mysql-replication/</link>
	<description>Public Cloud Solution by ServerStadium</description>
	<lastBuildDate>Thu, 04 Jan 2024 01:53:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://serverstadium.com/wp-content/uploads/2023/04/cropped-favicon-1-32x32.png</url>
	<title>MySQL Replication Archives - ServerStadium</title>
	<link>https://serverstadium.com/knowledge-base/tag/mysql-replication/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Setting Up MySQL Master-Slave Replication on ServerStadium VMs</title>
		<link>https://serverstadium.com/knowledge-base/setting-up-mysql-master-slave-replication-on-serverstadium-vms/</link>
		
		<dc:creator><![CDATA[Brian K]]></dc:creator>
		<pubDate>Thu, 04 Jan 2024 01:53:44 +0000</pubDate>
				<guid isPermaLink="false">https://serverstadium.com/?post_type=epkb_post_type_1&#038;p=11756</guid>

					<description><![CDATA[<p>MySQL Master-Slave replication involves one database server (the Master) sending updates to one or more database servers (the Slaves). This guide will walk you through setting up this configuration using ServerStadium VM instances. Prerequisites A ServerStadium account and at least two VM instances. Set these up through ServerStadium Cloud Services. Basic knowledge of MySQL and&#8230;</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/setting-up-mysql-master-slave-replication-on-serverstadium-vms/">Setting Up MySQL Master-Slave Replication on ServerStadium VMs</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>MySQL Master-Slave replication involves one database server (the Master) sending updates to one or more database servers (the Slaves). This guide will walk you through setting up this configuration using ServerStadium VM instances.</p>
<h3>Prerequisites</h3>
<ul>
<li>A ServerStadium account and at least two VM instances. Set these up through <a href="https://serverstadium.com/" target="_new" rel="noopener">ServerStadium Cloud Services</a>.</li>
<li>Basic knowledge of MySQL and Linux server management.</li>
</ul>
<h3>Step 1: Setting Up the MySQL Master Server</h3>
<ol>
<li><strong>Install MySQL</strong>: On your first VM (the Master), install MySQL:<div class="shortcode-code">
<p>sudo apt update<br />
sudo apt install mysql-server</p></div></li>
<li><strong>Configure MySQL for Replication</strong>: Open the MySQL configuration file:<br />
<div class="shortcode-code">
<p>sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf</p></div><br />
Add or modify the following lines:<br />
<div class="shortcode-code">
<p>server-id = 1<br />
log_bin = /var/log/mysql/mysql-bin.log<br />
binlog_do_db = my_database</p></div><br />
Replace <code>my_database</code> with the name of your database. Save and exit the file.</li>
<li><strong>Restart MySQL</strong>:<br />
<div class="shortcode-code">
<p>sudo systemctl restart mysql</p></div></li>
<li><strong>Create a Replication User</strong>:
<p>Access MySQL:<br />
<div class="shortcode-code">
<p>mysql -u root -p</p></div><br />
Then run:<br />
<div class="shortcode-code">
<p>CREATE USER &#039;replicator&#039;@&#039;%&#039; IDENTIFIED WITH mysql_native_password BY &#039;password&#039;;<br />
GRANT REPLICATION SLAVE ON *.* TO &#039;replicator&#039;@&#039;%&#039;;<br />
FLUSH PRIVILEGES;</p></div><br />
Replace <code>'password'</code> with a strong password.</li>
<li><strong>Lock the Database for Export</strong>:
<p>In the MySQL prompt, run:<br />
<div class="shortcode-code">
<p>FLUSH TABLES WITH READ LOCK;<br />
SHOW MASTER STATUS;</p></div><br />
Note the file name and position. You will need these for setting up the Slave.</li>
</ol>
<h3>Step 2: Setting Up the MySQL Slave Server</h3>
<ol>
<li><strong>Install MySQL on the Slave Server</strong>:
<p>Repeat the same installation process on your second VM (the Slave).</li>
<li><strong>Configure the Slave Server</strong>:
<p>Open the MySQL configuration:<br />
<div class="shortcode-code">
<p>sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf</p></div><br />
Add or modify:<br />
<div class="shortcode-code">
<p>server-id = 2<br />
relay_log = /var/log/mysql/mysql-relay-bin.log<br />
log_bin = /var/log/mysql/mysql-bin.log<br />
binlog_do_db = my_database</p></div><br />
Restart MySQL:<br />
<div class="shortcode-code">
<p>sudo systemctl restart mysql</p></div></li>
</ol>
<h3>Step 3: Synchronize the Databases</h3>
<ol>
<li><strong>Export the Database from the Master</strong>:
<p>On the Master server, export your database:<br />
<div class="shortcode-code">
<p>mysqldump -u root -p &#8211;opt my_database &gt; my_database.sql</p></div></li>
<li><strong>Transfer the Database Dump to the Slave Server</strong>:
<p>Use <code>scp</code> or a similar tool to transfer <code>my_database.sql</code> to the Slave server.</li>
<li><strong>Import the Database on the Slave Server</strong>:
<p>On the Slave server, import the database:<br />
<div class="shortcode-code">
<p>mysql -u root -p my_database &lt; my_database.sql</p></div></li>
</ol>
<h3>Step 4: Establish Replication</h3>
<ol>
<li><strong>Configure the Slave Server</strong>:
<p>On the Slave server, open the MySQL prompt:<br />
<div class="shortcode-code">
<p>mysql -u root -p</p></div><br />
Run:<br />
<div class="shortcode-code">
<p>STOP SLAVE;<br />
CHANGE MASTER TO MASTER_HOST=&#039;master_ip&#039;, MASTER_USER=&#039;replicator&#039;, MASTER_PASSWORD=&#039;password&#039;, MASTER_LOG_FILE=&#039;recorded_log_file_name&#039;, MASTER_LOG_POS=recorded_log_position;<br />
START SLAVE;</p></div><br />
Replace <code>master_ip</code>, <code>recorded_log_file_name</code>, <code>recorded_log_position</code>, and <code>password</code> with the appropriate values.</li>
<li><strong>Verify Replication Status</strong>:
<p>Still in the MySQL prompt on the Slave, check the replication status:<br />
<div class="shortcode-code">
<p>&lt;span class=&quot;hljs-keyword&quot;&gt;SHOW&lt;/span&gt; SLAVE STATUS\G</p></div><br />
Look for <code>Slave_IO_Running</code> and <code>Slave_SQL_Running</code> both being set to <code>Yes</code>.</li>
</ol>
<h3>Conclusion</h3>
<p>You&#8217;ve successfully set up MySQL Master-Slave replication across ServerStadium VMs. This configuration ensures that your databases are synchronized, providing a foundation for high availability and data redundancy.</p>
<p>For more resources or assistance, visit our <a href="https://serverstadium.com/knowledge-base/" target="_new" rel="noopener">knowledge base</a> or contact our support team.</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/setting-up-mysql-master-slave-replication-on-serverstadium-vms/">Setting Up MySQL Master-Slave Replication on ServerStadium VMs</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
