{"id":14275,"date":"2024-03-15T08:49:32","date_gmt":"2024-03-15T08:49:32","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/"},"modified":"2025-08-06T06:28:45","modified_gmt":"2025-08-06T06:28:45","slug":"how-to-set-up-mysql-master-slave-replication","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/","title":{"rendered":"MySQL Master-Slave Replication Setup"},"content":{"rendered":"<p>To set up MySQL master-slave replication, you need to follow the following steps:<\/p>\n<ol>\n<li>Make sure that MySQL is installed on both the primary server and the secondary server.<\/li>\n<li>Modify the configuration file my.cnf on the master server to enable the binary logging feature. Once you open the configuration file, locate the [mysqld] section and add the following content below it.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code>server-id = 1\r\nlog-bin = \/var\/log\/mysql\/mysql-bin.log\r\n<\/code><\/pre>\n<p>The server-id is used to identify the unique ID of the main server and can be set to any value, as long as it is not the same as the ID of the secondary server. log-bin specifies the path and filename for the binary log.<\/p>\n<ol>\n<li>Restart the main server to apply the configuration.<\/li>\n<li>Create a replication account on the master server and grant replication permissions. Open the MySQL client and execute the following SQL statement:<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code>CREATE USER 'replication'@'\u4ece\u670d\u52a1\u5668IP\u5730\u5740' IDENTIFIED BY '\u5bc6\u7801';\r\nGRANT REPLICATION SLAVE ON *.* TO 'replication'@'\u4ece\u670d\u52a1\u5668IP\u5730\u5740';\r\nFLUSH PRIVILEGES;\r\n<\/code><\/pre>\n<p>Replace the server IP address with the actual IP address of the server, and replace the password with the password of the copied account.<\/p>\n<ol>\n<li>Execute the command SHOW MASTER STATUS on the primary server, and make a note of the values for File and Position in the results.<\/li>\n<li>When modifying the configuration file my.cnf on the server, add the following content:<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code>server-id = 2\r\n<\/code><\/pre>\n<p>The server-id is used to identify the unique ID of the slave server, it can be set to any value, but it cannot be the same as the ID of the master server.<\/p>\n<ol>\n<li>Restart the server for the configuration to take effect.<\/li>\n<li>Execute the following command on the server:<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code>STOP SLAVE;\r\nCHANGE MASTER TO MASTER_HOST='\u4e3b\u670d\u52a1\u5668IP\u5730\u5740', MASTER_USER='replication', MASTER_PASSWORD='\u5bc6\u7801', MASTER_LOG_FILE='\u4e3b\u670d\u52a1\u5668\u4e0a\u7684File\u503c', MASTER_LOG_POS=\u4e3b\u670d\u52a1\u5668\u4e0a\u7684Position\u503c;\r\nSTART SLAVE;\r\n<\/code><\/pre>\n<p>Replace the main server&#8217;s IP address with the actual IP address of the main server, replace the password with the password of the copied account, and replace the File and Position values on the main server with the values recorded in step 5.<\/p>\n<ol>\n<li>Display the status of the slave server.<\/li>\n<li>The Slave I\/O process is functioning.<\/li>\n<li>The SQL process for the slave is currently running.<\/li>\n<li>Certainly.<\/li>\n<\/ol>\n<p>After completing the above steps, the MySQL master-slave replication has been successfully set up. Data updates on the master server will be automatically synchronized to the slave server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To set up MySQL master-slave replication, you need to follow the following steps: Make sure that MySQL is installed on both the primary server and the secondary server. Modify the configuration file my.cnf on the master server to enable the binary logging feature. Once you open the configuration file, locate the [mysqld] section and add [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[19237,5382,19236,4226,4399],"class_list":["post-14275","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-binary-logging","tag-database-replication","tag-master-slave-setup","tag-mysql-configuration","tag-mysql-replication"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MySQL Master-Slave Replication Setup - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Step-by-step guide to configure MySQL master-slave replication. Covers server setup, binary logs, and my.cnf configuration.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL Master-Slave Replication Setup\" \/>\n<meta property=\"og:description\" content=\"Step-by-step guide to configure MySQL master-slave replication. Covers server setup, binary logs, and my.cnf configuration.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-15T08:49:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-06T06:28:45+00:00\" \/>\n<meta name=\"author\" content=\"Liam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Liam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/\"},\"author\":{\"name\":\"Liam\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671\"},\"headline\":\"MySQL Master-Slave Replication Setup\",\"datePublished\":\"2024-03-15T08:49:32+00:00\",\"dateModified\":\"2025-08-06T06:28:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/\"},\"wordCount\":346,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"binary logging\",\"database replication\",\"master-slave setup\",\"MySQL configuration\",\"MySQL replication\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/\",\"name\":\"MySQL Master-Slave Replication Setup - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-15T08:49:32+00:00\",\"dateModified\":\"2025-08-06T06:28:45+00:00\",\"description\":\"Step-by-step guide to configure MySQL master-slave replication. Covers server setup, binary logs, and my.cnf configuration.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Master-Slave Replication Setup\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671\",\"name\":\"Liam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g\",\"caption\":\"Liam\"},\"sameAs\":[\"http:\/\/Wilson\"],\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/liamwilson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"MySQL Master-Slave Replication Setup - Blog - Silicon Cloud","description":"Step-by-step guide to configure MySQL master-slave replication. Covers server setup, binary logs, and my.cnf configuration.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/","og_locale":"en_US","og_type":"article","og_title":"MySQL Master-Slave Replication Setup","og_description":"Step-by-step guide to configure MySQL master-slave replication. Covers server setup, binary logs, and my.cnf configuration.","og_url":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-15T08:49:32+00:00","article_modified_time":"2025-08-06T06:28:45+00:00","author":"Liam","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Liam","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/"},"author":{"name":"Liam","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671"},"headline":"MySQL Master-Slave Replication Setup","datePublished":"2024-03-15T08:49:32+00:00","dateModified":"2025-08-06T06:28:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/"},"wordCount":346,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["binary logging","database replication","master-slave setup","MySQL configuration","MySQL replication"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/","url":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/","name":"MySQL Master-Slave Replication Setup - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-15T08:49:32+00:00","dateModified":"2025-08-06T06:28:45+00:00","description":"Step-by-step guide to configure MySQL master-slave replication. Covers server setup, binary logs, and my.cnf configuration.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-to-set-up-mysql-master-slave-replication\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"MySQL Master-Slave Replication Setup"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/23786905eb7b377f45ddb01c17da7671","name":"Liam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8d37ed3e7f770dde8bf069ba0b4298688028c3abaacf1131742fc1352d174ebd?s=96&d=mm&r=g","caption":"Liam"},"sameAs":["http:\/\/Wilson"],"url":"https:\/\/www.silicloud.com\/blog\/author\/liamwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/14275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=14275"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/14275\/revisions"}],"predecessor-version":[{"id":158305,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/14275\/revisions\/158305"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=14275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=14275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=14275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}