{"id":6185,"date":"2016-08-30T18:08:56","date_gmt":"2016-08-30T10:08:56","guid":{"rendered":"http:\/\/rmohan.com\/?p=6185"},"modified":"2016-08-30T18:08:56","modified_gmt":"2016-08-30T10:08:56","slug":"deploy-mysql-master-slave-on-centos7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6185","title":{"rendered":"Deploy MySQL master-slave on CentOS7"},"content":{"rendered":"<h1 class=\"aTitle\">Deploy MySQL master-slave on CentOS7<\/h1>\n<p>2 Locate the directory my.cnf file resides:<br \/>\nMySQL &#8211;help | grep my.cnf<br \/>\ngeneral my.cnf are located in \/etc\/directory;<\/p>\n<p>3 with vim open MySQL configuration file my.cnf:<br \/>\nvim \/etc\/my.cnf<\/p>\n<p>4 Locate the [mysqld] and subsequently add the following configuration:<br \/>\n# uniquely identifies this MySQL server, the default value is 1, the general IP terminal belongs value<br \/>\nserver-id=1<br \/>\n# binary log file name, MySQL master server must enable this configuration<br \/>\nlog-bin=master-bin-log<br \/>\n# master server in the MySQL database name involved in master-slave replication; if there are multiple databases, this parameter can have multiple, one per line, divisions corresponding to different database<br \/>\nbinlog-do-db=db_master_slave<br \/>\n# master the MySQL server binary log file name in the index of<br \/>\nlog-bin-index=master-bin-log.index<\/p>\n<p>Also open from 5 in the MySQL server using vim my.cnf file, locate the [mysqld], and add the following configuration at the rear:<br \/>\n# uniquely identifies this MySQL server, the default value is 1, the general IP terminal belongs value<br \/>\nserver-id=2<br \/>\n# log index file name from the MySQL server the above mentioned id<br \/>\nrelay-log-index=slave-relay-log.index<br \/>\n# log file name from the MySQL server<br \/>\nrelay-log=slave-relay-log<\/p>\n<p>6, respectively, to create a database db_master_slave on MySQL master and slave servers:<br \/>\nthe Create Database db_master_slave;<br \/>\ncreate database db_master_slave;<\/p>\n<p>7 Create user user_master on MySQL master server, and set a password Password_Master_123456: the Create the User &#8216;user_master&#8217; @ &#8216;%&#8217; IDENTIFIED by &#8216;Password_Master_123456&#8217;;<br \/>\ncreate user &#8216;user_master&#8217;@&#8217;%&#8217; identified by &#8216;Password_Master_123456&#8217;;<\/p>\n<p>8 on MySQL master server for users user_master Empowering all rights db_master_slave database:<br \/>\ngrant all on db_master_slave.* to &#8216;user_master&#8217;@&#8217;%&#8217;;<\/p>\n<p>9 On the MySQL master server for the local user access privileges assigned user_master:<br \/>\ngrant all privileges on db_master_slave.* to &#8216;user_master&#8217;@&#8217;localhost&#8217; identified by &#8216;Password_Master_123456&#8217;;<\/p>\n<p>10 Authorized MySQL slave servers on a MySQL master server can access the host server by user_master User:<br \/>\ngrant replication slave on *.* to &#8216;user_master&#8217;@&#8217;%&#8217; identified by &#8216;Password_Master_123456&#8242; with grant option;<\/p>\n<p>11 On the MySQL master and slave servers are restarted MySQL service:<br \/>\nclosed MySQL service:<br \/>\nservice mysqld stop<br \/>\nopen MySQL service:<br \/>\nservice mysqld start<br \/>\nrestart the MySQL service:<br \/>\nservice mysql restart<\/p>\n<p>12 On the MySQL master and slave servers are entered into the database db_master_slave:<br \/>\nuse db_master_slave;<br \/>\ncreate table t_user(id int(3), name varchar(128));<\/p>\n<p>13 See MySQL master server status:<br \/>\nshow master status;<br \/>\nthe value of its properties and master_log_pos master_log_file property and records;<\/p>\n<p>14 executed on a MySQL slave service as follows:<br \/>\nChange to Master MASTER_HOST =&#8217;192.168.1.10&#8242;, \/\/ the MySQL Master server the IP<br \/>\nMASTER_PORT=3306,<br \/>\nMASTER_USER=&#8217;user_master&#8217;,<br \/>\nmaster_password=&#8217;Password_Master_123456&#8242;,<br \/>\nMASTER_LOG_FILE=&#8217;Master-bin-log.000004 &#8216;, \/\/ MySQL master server master_log_file value<br \/>\nmaster_log_pos=654; \/\/ value of MySQL master server master_log_pos<\/p>\n<p>15 db_master_slave library MySQL master server to add data to the user name T_USER:<br \/>\nmysql&gt; insert into t_user(id, name) values(1, &#8216;idea1&#8217;);<br \/>\nmysql&gt; select * from t_user;<\/p>\n<p>16 db_master_slave library MySQL slave server to add data to the user name T_USER:<br \/>\nmysql&gt; insert into t_user(id, name) values(1, &#8216;idea1&#8217;);<br \/>\nmysql&gt; select * from t_user;<\/p>\n<p>17 MySQL slave servers how to discover:<br \/>\nslave_IO_running = NO<br \/>\nthen execute the following command:<br \/>\nmysql&gt; stop slave;<br \/>\nmysql&gt; start slave;<\/p>\n<p>18 See MySQL runtime server_id values:<br \/>\nshow variables like &#8216;server_id&#8217;;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Deploy MySQL master-slave on CentOS7 <\/p>\n<p>2 Locate the directory my.cnf file resides: MySQL &#8211;help | grep my.cnf general my.cnf are located in \/etc\/directory;<\/p>\n<p>3 with vim open MySQL configuration file my.cnf: vim \/etc\/my.cnf<\/p>\n<p>4 Locate the [mysqld] and subsequently add the following configuration: # uniquely identifies this MySQL server, the default value is 1, the [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6185"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6185"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6185\/revisions"}],"predecessor-version":[{"id":6186,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6185\/revisions\/6186"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}