<input type="hidden" id="_wpnonce" name="_wpnonce" value="c34aa85f7e" /><input type="hidden" name="_wp_http_referer" value="/blog/wp-json/wp/v2/posts/2177" /><input type="hidden" id="_wpnonce" name="_wpnonce" value="c34aa85f7e" /><input type="hidden" name="_wp_http_referer" value="/blog/wp-json/wp/v2/posts/2177" />{"id":2177,"date":"2014-04-04T12:57:27","date_gmt":"2014-04-04T01:57:27","guid":{"rendered":"https:\/\/www.businesslegions.com\/blog\/?p=2177"},"modified":"2014-04-04T12:57:27","modified_gmt":"2014-04-04T01:57:27","slug":"mysql-database-replication","status":"publish","type":"post","link":"https:\/\/www.businesslegions.com\/blog\/2014\/04\/04\/mysql-database-replication\/","title":{"rendered":"MySql database replication"},"content":{"rendered":"<!--CusAds0--><p>This was my first time setting up a MySql Database Replication instance between two servers. The instructions that I used from the mysql.com (<a title=\"How to setup replication\" href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/replication-howto.html\">How to set up Replication<\/a>) was straight forward but there were a few gotcha&#8217;s which I decided to document in case I forget. If you&#8217;re an expert in this area and the instructions are incorrect please contact me so I can amend and update.<\/p>\n<p><strong>On the Master Server\u00a0<\/strong><\/p>\n<p>This is the server which will have the master database. Master meaning that the information in this database will be replicated and copied to the slave database.<\/p>\n<p><em>Create replication user account<\/em><strong>\u00a0<\/strong><\/p>\n<p>Login to phpMyAdmin and click the Replication button at the top menu<\/p>\n<p>Click on Add slave replication user<\/p>\n<div id=\"attachment_2198\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/MySQL-Add-slave-replication-user.png?strip=all&w=2560\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2198\" class=\"size-medium wp-image-2198\" alt=\"MySQL Add slave replication user\" src=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/MySQL-Add-slave-replication-user-300x242.png?strip=all\" width=\"300\" height=\"242\" \/><\/a><p id=\"caption-attachment-2198\" class=\"wp-caption-text\">MySQL Add slave replication user<\/p><\/div>\n<p>Enter all details (username, password)<\/p>\n<div id=\"attachment_2199\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/MySQL-Add-slave-replication-user-details.png?strip=all&w=2560\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2199\" class=\"size-medium wp-image-2199\" alt=\"MySQL Add slave replication user details\" src=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/MySQL-Add-slave-replication-user-details-300x243.png?strip=all\" width=\"300\" height=\"243\" \/><\/a><p id=\"caption-attachment-2199\" class=\"wp-caption-text\">MySQL Add slave replication user details<\/p><\/div>\n<div id=\"attachment_2200\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/MySQL-Add-slave-replication-user-list.png?strip=all&w=2560\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2200\" class=\"size-medium wp-image-2200\" alt=\"MySQL Add slave replication user list\" src=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/MySQL-Add-slave-replication-user-list-300x122.png?strip=all\" width=\"300\" height=\"122\" \/><\/a><p id=\"caption-attachment-2200\" class=\"wp-caption-text\">MySQL Add slave replication user list<\/p><\/div>\n<p>This is the account that will be used on the slaves to connect to the master to authenticate and replicate the tables.<\/p>\n<p><em>Export Database<\/em><\/p>\n<p>According to the instructions from Mysql.com you need to flush the tables with read lock. To do this start mysql and enter:<\/p>\n<pre>mysql&gt; <strong><code>FLUSH TABLES WITH READ LOCK;<\/code><\/strong><\/pre>\n<p>Now if your database is empty I don&#8217;t believe you need to run this step.<\/p>\n<p>Then you need to export the database by using the following command:<\/p>\n<pre>shell&gt; <strong><code>mysqldump --all-databases --master-data &gt; dbdump.db<\/code><\/strong><\/pre>\n<p>It&#8217;s important you use &#8211;master-data so that it locks all tables in a seperate session. If you have a large database you can use the command gzip<\/p>\n<pre>shell&gt; <strong><code>mysqldump --all-databases --master-data | gzip &gt; dbdump.db<\/code><\/strong><\/pre>\n<p>That&#8217;s pretty much all you need to do on the master server. You also need to make sure that your firewall allows incoming connection using port 3306.<\/p><!--CusAds0-->\n<p>Once you have configured the slave you can check the status on master to see which clients are replicating by clicking on Show Connected Slaves.<\/p>\n<div id=\"attachment_2201\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/MySQL-Show-Connected-slaves.png?strip=all&w=2560\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2201\" class=\"size-medium wp-image-2201\" alt=\"MySQL Show Connected slaves\" src=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/MySQL-Show-Connected-slaves-300x144.png?strip=all\" width=\"300\" height=\"144\" \/><\/a><p id=\"caption-attachment-2201\" class=\"wp-caption-text\">MySQL Show Connected slaves<\/p><\/div>\n<p>&nbsp;<\/p>\n<p><strong><\/strong><strong>On the slave server<\/strong><\/p>\n<p>You will need to import the mysql dump. So follow these steps<\/p>\n<ol type=\"a\">\n<li>Start the slave, using the\u00a0<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/replication-options-slave.html#option_mysqld_skip-slave-start\"><code>--skip-slave-start<\/code><\/a>\u00a0option so that replication does not start.<\/li>\n<li>Import the dump file:\n<pre>shell&gt; <strong><code>mysql &lt; fulldb.dump<\/code><\/strong><\/pre>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Login to myphpadmin and click the replication button at the top.<\/p>\n<p>Click configure<\/p>\n<div id=\"attachment_2205\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/mysql-slave-replication-configure.jpg?strip=all&w=2560\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2205\" class=\"size-medium wp-image-2205\" alt=\"mysql slave replication configure\" src=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/mysql-slave-replication-configure-300x62.jpg?strip=all\" width=\"300\" height=\"62\" \/><\/a><p id=\"caption-attachment-2205\" class=\"wp-caption-text\">mysql slave replication configure<\/p><\/div>\n<p>Enter the details that was used on the master server.<\/p>\n<div>\n<dl id=\"attachment_2204\">\n<dt><a href=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/mysql-slave-replication-configure-settings.jpg?strip=all&w=2560\"><img decoding=\"async\" alt=\"mysql slave replication configure settings\" src=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/mysql-slave-replication-configure-settings-300x186.jpg?strip=all\" width=\"300\" height=\"186\" \/><\/a><\/dt>\n<dd>mysql slave replication configure settings<\/dd>\n<\/dl>\n<\/div>\n<p>Click Go and check the slave status<\/p>\n<div>\n<div id=\"attachment_2206\" style=\"width: 243px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/mysql-slave-replication-check-slave-status.jpg?strip=all&w=2560\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2206\" class=\"size-medium wp-image-2206\" alt=\"mysql slave replication check slave status\" src=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2014\/04\/mysql-slave-replication-check-slave-status-233x300.jpg?strip=all\" width=\"233\" height=\"300\" \/><\/a><p id=\"caption-attachment-2206\" class=\"wp-caption-text\">mysql slave replication check slave status<\/p><\/div>\n<\/div>\n<p>Once you have added the master settings you will have the option to check the master status<\/p>\n<p>Add\u00a0\u00a0&#8211;report-host=host_name in the my.ini (I&#8217;m using WAMP). The hostname you can change to a unique word to identify your slaves.<\/p>\n<p>I hope this has helped someone start replicating their mysql database. If there&#8217;s anything that I can improve in this post then please leave me a comment as I&#8217;m no expert in this area.<\/p>\n<p><strong>NOTE: I was getting some duplicate 1062 errors when Importing the dump file, so I just added this line to the my.ini file.<\/strong><\/p>\n<p>slave-skip-errors = 1062<\/p>\n<p>&nbsp;<\/p>\n<div class=\"lt-box\" style=\"border:1px solid #1d6a9e\"><div class=\"lt-box-title\" style=\"background-color:#2485C6;border-top:1px solid #a7cee8;text-shadow:1px 1px 0 #0b283b\">DO YOU LIKE WHAT YOU'VE READ?<\/div><div class=\"lt-box-content\">Join our subscription list and receive our content right in your mailbox. If you like to receive some Great deals our Freebies then subscribe now!\r\n\r\n<p><div class=\"tnp tnp-subscription \">\n<form method=\"post\" action=\"https:\/\/www.businesslegions.com\/blog\/wp-admin\/admin-ajax.php?action=tnp&amp;na=s\">\n<input type=\"hidden\" name=\"nlang\" value=\"\">\n<div class=\"tnp-field tnp-field-firstname\"><label for=\"tnp-1\">Name<\/label>\n<input class=\"tnp-name\" type=\"text\" name=\"nn\" id=\"tnp-1\" value=\"\" placeholder=\"\"><\/div>\n<div class=\"tnp-field tnp-field-email\"><label for=\"tnp-2\">Email<\/label>\n<input class=\"tnp-email\" type=\"email\" name=\"ne\" id=\"tnp-2\" value=\"\" placeholder=\"\" required><\/div>\n<div class=\"tnp-field tnp-field-button\" style=\"text-align: left\"><input class=\"tnp-submit\" type=\"submit\" value=\"Subscribe\" style=\"\">\n<\/div>\n<\/form>\n<\/div>\n<\/p>\r\n\r\n<\/div><\/div><!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>This was my first time setting up a MySql Database Replication instance between two servers. The instructions that I used from the mysql.com (How to set up Replication) was straight forward but there were a few gotcha&#8217;s which I decided to document in case I forget. If you&#8217;re an expert in this area and the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2206,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2177","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/posts\/2177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/comments?post=2177"}],"version-history":[{"count":6,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/posts\/2177\/revisions"}],"predecessor-version":[{"id":2927,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/posts\/2177\/revisions\/2927"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/media\/2206"}],"wp:attachment":[{"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/media?parent=2177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/categories?post=2177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/tags?post=2177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}