{"id":33,"date":"2009-11-04T07:56:02","date_gmt":"2009-11-04T07:56:02","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=33"},"modified":"2023-05-12T11:10:31","modified_gmt":"2023-05-12T11:10:31","slug":"quick-multi-mysql-server-installation-with-master-master-replication-on-same-windows-box","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/quick-multi-mysql-server-installation-with-master-master-replication-on-same-windows-box","title":{"rendered":"Install 2 MySQL Server instances replication on Windows"},"content":{"rendered":"\n<p>At times you need to install multiple MySQL instances on same machine. This article is a brief step-by-step tutorial on the subject task which is divided into the following main parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Installing two MySQL Server Instances<\/li>\n\n\n\n<li>Setting up master-slave replication<\/li>\n\n\n\n<li>Setting up slave-master replication<\/li>\n<\/ul>\n\n\n\n<p>Let&#8217;s begin covering those points&#8230;<\/p>\n\n\n\n<p><strong>Installing Two MySQL Server Instances on Windows:<br><\/strong><br>1. Install MySQL:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download MySQL Binaries from dev.mysql.com.<\/li>\n\n\n\n<li>Install normal MSI Package of mysql. (I used: mysql-essential-5.0.83-win32).<\/li>\n<\/ul>\n\n\n\n<p><em>* Following MSI Installation is quite easy, proceed and finish the installation.<br>This server will be installed on default 3306 port with all windows default settings.<\/em><\/p>\n\n\n\n<p>2. Register\/Install another MySQL instance:<\/p>\n\n\n\n<p>To have two servers we make sure to have separate values of port, datadir etc. Please check the configuration file for according changes.<\/p>\n\n\n\n<p>Create a duplicate of \/etc\/my.cnf as \/etc\/my2.cnf and make according changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqld-nt.exe --install \"MySQL1\" --defaults-file=\"C:\\Program Files\\MySQL\\MySQL Server 5.0\\my2.ini\"<\/code><\/pre>\n\n\n\n<p>This will register the mysql1 service, and thus we&#8217;ll end up having two mysql instances on windows.<\/p>\n\n\n\n<p>3. Start Both MySQL Servers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>net start mysql<br>net start mysql1<\/code><\/pre>\n\n\n\n<p>4. Check connecting client from command prompt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -uroot -p --port=3306<br>mysql -uroot -p --port=3307<\/code><\/pre>\n\n\n\n<p><em>* It will prompt for password, on success you will end up logging in both mysql servers.<\/em><\/p>\n\n\n\n<p><strong>Setting up Master-Master Replication on Windows &#8211; Single machine:<br><\/strong><\/p>\n\n\n\n<p>Setting up Master-Master Replication mainly consists of getting both servers to perform Master and Slave Replication Roles.<\/p>\n\n\n\n<p>For replication I have used database named &#8216;master&#8217; having table named &#8216;test&#8217; with following structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Create database master;<br>Use master;<br>CREATE TABLE `temp` (<br>`id` int(10) NOT NULL auto_increment,<br>PRIMARY KEY&nbsp; (`id`)<br>) ENGINE=MyISAM DEFAULT CHARSET=latin1;<\/code><\/pre>\n\n\n\n<p>Here we&#8217;ve two MySQL server instances, namely mysql and mysql1.<\/p>\n\n\n\n<p>We will setup Master-Slave Replication from mysql1 to mysql. Later we will setup Master-Slave Replication from mysql to mysql1.<br><em>For your reference please check the appendix section for sample configuration files along with below mentioned instructions.<\/em><\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">1. Setting Master Slave &#8220;mysql1 &#8211;&gt; mysql&#8221;:<\/span><\/strong> <strong><span style=\"text-decoration: underline;\"><br><\/span><\/strong><br>Considering:<\/p>\n\n\n\n<p><em>mysql1 @ port: 3307 as Master<br>mysql @ port: 3306 as Slave <\/em><\/p>\n\n\n\n<p>&#8211; On mysql1(master): Add following line to my.ini:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>binlog-do-db=master<\/code><\/pre>\n\n\n\n<p>&#8211; We require a &#8216;Replication Slave&#8217; privileged user on Master for slave to connect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; Grant replication slave on *.* to 'replication1'@'localhost' identified by 'slave1';<\/code><\/pre>\n\n\n\n<p>On mysql(slave):<br>&#8211; Add following line to my.ini:<\/p>\n\n\n\n<p>#Conn. Pmtr for slave:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>master-host = localhost\nmaster-user = replication1\nmaster-password = slave1\nmaster-port = 3307<\/code><\/pre>\n\n\n\n<p>*It&#8217;s not a good idea to add such parameters in configuration file; but this is just learning purpose. Use CHANGE MASTER&amp; command.<\/p>\n\n\n\n<p>&#8211; Start Slave Server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>net start mysql<\/code><\/pre>\n\n\n\n<p>&#8211; On Slave Client:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt;Start Slave;<\/code><\/pre>\n\n\n\n<p><em>** Check for working Master-Slave Replication.**<br>** Stop both MySQL Servers **<\/em><\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">2. Setting Slave Master &#8220;mysql1 &lt;&#8211; mysql&#8221; :<\/span><\/strong><strong><span style=\"text-decoration: underline;\"><br><\/span><br><\/strong><br>Considering:<\/p>\n\n\n\n<p><em>mysql1 @ port: 3307 as Slave<br>mysql @ port: 3306 as Master <\/em><\/p>\n\n\n\n<p>&#8211; On mysql(master) Add following line to my.cnf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>binlog-do-db=master<\/code><\/pre>\n\n\n\n<p>&#8211; Start Master Server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>net start mysql1<\/code><\/pre>\n\n\n\n<p>&#8211; We require a &#8216;Replication Slave&#8217; privileged user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; Grant replication slave on *.* to 'replication2'@'localhost' identified by 'slave2';<\/code><\/pre>\n\n\n\n<p>&#8211; On mysql1 (slave):<br>Add following line to my.cnf:<\/p>\n\n\n\n<p>#Conn. Pmtr for slave:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>master-host = localhost<br>master-user = replication2<br>master-password = slave2<br>master-port = 3306<\/code><\/pre>\n\n\n\n<p>&#8211; Start Slave Server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>net start mysql<\/code><\/pre>\n\n\n\n<p>&#8211; On Slave client:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt;Start Slave;<\/code><\/pre>\n\n\n\n<p><em>** Check for working Master-Slave **<br>** Check for working Master-Master **<\/em><\/p>\n\n\n\n<p>And that&#8217;s it. &nbsp;We now have two different instances of MySQL server running with a Master-Master replication scheme. &nbsp;Hopefully, you found this tutorial helpful. &nbsp;Please see examples of the final configuration files in the appendix below along with references for more information regarding this topic.<\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">Appendix: Configuration Files for master-master mysql setup:<\/span><\/strong><\/p>\n\n\n\n<p><em>Following is the my.ini [configuration] file for first MySQL Server Instance:<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>##my.ini for mysql (Regularly installed):\n&#91;client]\nport=3306\n&#91;mysqld]\nserver-id=2\nport=3306\n# Replication\nlog-bin=binlog\n\n\n#For this as master:\nbinlog-do-db=master\nbinlog-ignore-db=mysql\nbinlog-ignore-db=test\n\n#Conn. Pmtr for slave:\n\nmaster-host = localhost\nmaster-user = replication1\nmaster-password = slave1\nmaster-port = 3307\nbasedir=\"C:\/Program Files\/MySQL\/MySQL Server 5.0\/\"\ndatadir=\"C:\/Program Files\/MySQL\/MySQL Server 5.0\/Data\/\"\nauto_increment_increment=1\nauto_increment_offset=1<\/code><\/pre>\n\n\n\n<p><em>Following is the my2.ini [configuration] file for second MySQL instance named &#8220;mysql1&#8221;:<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>##my2.ini for Mysql1:<br>&#91;client]<br>port=3307<br>&#91;mysqld]<br>server-id=1<br>port=3307<br># Replication<br>log-bin=binlog<br>#For this as master:<br>binlog-do-db=master<br>binlog-ignore-db=mysql<br>binlog-ignore-db=test<br>#Conn. Pmtr for slave:<br>master-host = localhost<br>master-user = replication2<br>master-password = slave2<br>master-port = 3306<br>basedir=\"C:\/Program Files\/MySQL\/MySQL Server 5.0\/\"<br>datadir=\"C:\/Program Files\/MySQL\/MySQL Server 5.0\/Data1\/\"<br>auto_increment_increment=1<br>auto_increment_offset=2<\/code><\/pre>\n\n\n\n<p><object id=\"Player_69391845-f3a3-4252-bd26-9c83e7b0324e\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\" width=\"300px\" height=\"250px\"><param name=\"quality\" value=\"high\"><param name=\"bgcolor\" value=\"#FFFFFF\"><param name=\"allowscriptaccess\" value=\"always\"><param name=\"src\" value=\"http:\/\/ws.amazon.com\/widgets\/q?ServiceVersion=20070822&amp;MarketPlace=US&amp;ID=V20070822%2FUS%2Fhttpkedarnitt-20%2F8003%2F69391845-f3a3-4252-bd26-9c83e7b0324e&amp;Operation=GetDisplayTemplate\"><param name=\"name\" value=\"Player_69391845-f3a3-4252-bd26-9c83e7b0324e\"><param name=\"align\" value=\"middle\"><embed id=\"Player_69391845-f3a3-4252-bd26-9c83e7b0324e\" type=\"application\/x-shockwave-flash\" src=\"http:\/\/ws.amazon.com\/widgets\/q?ServiceVersion=20070822&amp;MarketPlace=US&amp;ID=V20070822%2FUS%2Fhttpkedarnitt-20%2F8003%2F69391845-f3a3-4252-bd26-9c83e7b0324e&amp;Operation=GetDisplayTemplate\" name=\"Player_69391845-f3a3-4252-bd26-9c83e7b0324e\" allowscriptaccess=\"always\" bgcolor=\"#FFFFFF\" quality=\"high\" width=\"300px\" height=\"250px\" align=\"middle\"><\/object><\/p>\n\n\n\n<p><noscript>mce:0<\/noscript><\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">References:<\/span><\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/replication-howto.html<\/li>\n\n\n\n<li>http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/multiple-windows-servers.html<\/li>\n\n\n\n<li>http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/change-master-to.html<\/li>\n\n\n\n<li>http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/replication-options-master.html#sysvar_auto_increment_increment<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"At times you need to install multiple MySQL instances on same machine. This article is a brief step-by-step tutorial on the subject task which is divided into the following main&hellip;\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,377],"tags":[142,66,583,427,100],"class_list":{"0":"post-33","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-mysql","7":"category-mysql-articles","8":"tag-installation","9":"tag-master-master","10":"tag-multiple-instances-of-mysql","11":"tag-mysql","12":"tag-replication"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":5,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":2887,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions\/2887"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}