{"id":353,"date":"2010-07-20T05:48:00","date_gmt":"2010-07-20T11:48:00","guid":{"rendered":"http:\/\/blog.supportpro.com\/?p=353"},"modified":"2019-10-30T06:11:26","modified_gmt":"2019-10-30T12:11:26","slug":"one-way-replication-of-mysql-database","status":"publish","type":"post","link":"https:\/\/www.supportpro.com\/blog\/one-way-replication-of-mysql-database\/","title":{"rendered":"One way replication of mysql database:"},"content":{"rendered":"<p>Mysql replication help us in keeping the data replicated to one or more sites reliably with binary logs. Apart from good amount of advantages Mysql replication doesnt help with data corruption, since the corrupted data is replicated in all slaves. It is good to have periodic backup of database apart from replication.<\/p>\n<p><!--more--><\/p>\n<p>Replication Steps :<\/p>\n<ol>\n<li>Create database with same name on all servers:&gt; mysql -u db_user -p -e &#8220;CREATE DATABASE db_name&#8221;<\/li>\n<li>Create database user with replication privilege on master<br \/>\n&gt; GRANT REPLICATION SLAVE ON *.* TO &#8216;replication_user&#8217;@&#8217;replication_clients&#8221; IDENTIFIED BY &#8216;replication_password&#8217;This can be also supplied with particular database name with ;db_name.* instead of *.*<\/li>\n<li>Edit Mysql master configuration (my.cnf) to allow replication<br \/>\n[mysqld]<br \/>\nserver-id = 1 # Important with replication<br \/>\nlog-slave-updates<br \/>\nlog-bin = \/var\/lib\/mysql\/mysql-bin<br \/>\nlog-bin-index = \/var\/lib\/mysql\/mysql-bin.index<br \/>\nreplicate-do-db = db_name # specify the dbs to replicate<br \/>\nlog-warnings<br \/>\ninnodb_flush_log_at_trx_commit=1<br \/>\nsync-binlog=1<br \/>\ninnodb_safe_binlog<\/li>\n<li>Take dump of master db and put them on all replicas<br \/>\nuse db_name;<br \/>\nFLUSH TABLES WITH READ LOCK;<\/li>\n<\/ol>\n<p>$ mysqldump -u dbuser -p db_name &gt; db_dump.sql<br \/>\ninstall on slaves<br \/>\n$ mysql -u dbuser -p db_name &gt; db_dump.sql<\/p>\n<p>use db_name;<br \/>\nUNLOCK TABLES;<\/p>\n<p>5. Edit mysql configuration on replicas with master credentials<br \/>\n[mysqld]<br \/>\nold_passwords=1<br \/>\nserver-id=2<br \/>\ninnodb_file_per_table<br \/>\nlog-slave-updates<br \/>\nmaster-host = master_hostname<br \/>\nmaster-port = master_port<br \/>\nmaster-user = master_user<br \/>\nmaster-password = master_password<br \/>\nlog-bin = \/var\/lib\/mysql\/mysql-bin<br \/>\nlog-bin-index = \/var\/lib\/mysql\/mysql-bin.index<\/p>\n<p>Restart the Mysql daemon on all servers and check the replication status:<br \/>\nMaster: &gt; show master status;<br \/>\nReplicas: &gt; show slave status;<\/p>\n<p>If you require help, c<a href=\"https:\/\/www.supportpro.com\/requestquote.php\">ontact SupportPRO Server Admin<\/a><\/p>\n<p style=\"text-align: center;\"><!--HubSpot Call-to-Action Code --><span id=\"hs-cta-wrapper-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-wrapper\"><span id=\"hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-node hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\"><!-- [if lte IE 8]><\/p>\n\n\n\n\n\n<div id=\"hs-cta-ie-element\"><\/div>\n\n\n<![endif]--><a href=\"https:\/\/www.supportpro.com\/freecheckup.php\"><img decoding=\"async\" id=\"hs-cta-img-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-img\" style=\"border-width: 0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/9d590242-d641-4383-94b4-8cfd62f0af6b.png\" alt=\"Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value\" \/><\/a><\/span><script charset=\"utf-8\" src=\"https:\/\/js.hscta.net\/cta\/current.js\"><\/script><script type=\"text\/javascript\"> hbspt.cta.load(2725694, '9d590242-d641-4383-94b4-8cfd62f0af6b', {}); <\/script><\/span><!-- end HubSpot Call-to-Action Code --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mysql replication help us in keeping the data replicated to one or more sites reliably with binary logs. Apart from good amount of advantages Mysql replication doesnt help with data&hellip;<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-353","post","type-post","status-publish","format-standard","hentry","category-miscellaneous"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/comments?post=353"}],"version-history":[{"count":2,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/353\/revisions"}],"predecessor-version":[{"id":4474,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/353\/revisions\/4474"}],"wp:attachment":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media?parent=353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/categories?post=353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/tags?post=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}