{"id":209,"date":"2026-06-01T23:23:31","date_gmt":"2026-06-02T06:23:31","guid":{"rendered":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/"},"modified":"2026-06-01T23:23:31","modified_gmt":"2026-06-02T06:23:31","slug":"how-to-set-up-mysql-replication-master-slave-linux","status":"publish","type":"post","link":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/","title":{"rendered":"How to Set Up MySQL Replication (Master-Slave) on Linux"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>MySQL replication is the process of automatically copying data from one MySQL server (the master) to one or more other servers (the slaves). Changes made on the master \u2014 inserts, updates, deletes \u2014 get written to a binary log, and the slave reads that log and replays the same changes on its own copy of the data.<\/p>\n<p>You&#8217;ll want replication set up if you&#8217;re running a high-traffic site that needs read queries offloaded to a second server, if you need a live standby for failover, or if you want a replication target you can safely back up without locking your production database. It&#8217;s also common on <a href=\"https:\/\/www.hostandtech.com\/vps-ssd-servers\">VPS SSD Hosting<\/a> setups where you&#8217;re running your own database tier across two nodes.<\/p>\n<p>This guide covers classic async master-slave replication using binary logging, tested on MySQL 8.0 and MariaDB 10.6+ on Ubuntu 22.04 and AlmaLinux 9. GTID-based replication is covered in the notes \u2014 I&#8217;d recommend it for any new setup since it makes failover and re-synchronisation significantly less painful.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>Two Linux servers (master and slave) \u2014 both must be able to reach each other over TCP port <code class=\"\" data-line=\"\">3306<\/code>, or whatever port MySQL is bound to<\/li>\n<li>MySQL 8.0+ or MariaDB 10.5+ installed on both servers<\/li>\n<li>Root or <code class=\"\" data-line=\"\">sudo<\/code> access on both servers<\/li>\n<li>Identical MySQL\/MariaDB major versions on both nodes \u2014 replication from MySQL 8.0 master to 5.7 slave is not supported<\/li>\n<li>A consistent snapshot of the master database to seed the slave (covered in Step 5)<\/li>\n<li>Both servers should have their clocks synced via NTP \u2014 clock drift causes intermittent replication lag that&#8217;s annoying to diagnose<\/li>\n<\/ul>\n<h2>Step-by-Step Instructions<\/h2>\n<h3>Step 1: Configure the Master Server<\/h3>\n<p>Open the MySQL configuration file on the master. On Ubuntu\/Debian it&#8217;s typically <code class=\"\" data-line=\"\">\/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code>. On RHEL\/AlmaLinux it&#8217;s <code class=\"\" data-line=\"\">\/etc\/my.cnf<\/code> or <code class=\"\" data-line=\"\">\/etc\/my.cnf.d\/mysql-server.cnf<\/code>.<\/p>\n<p>Add or update the following under the <code class=\"\" data-line=\"\">[mysqld]<\/code> section:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-1\"><code class=\"\" data-line=\"\">[mysqld]\nserver-id = 1\nlog_bin = \/var\/log\/mysql\/mysql-bin.log\nbinlog_do_db = your_database_name\nbinlog_format = ROW\ngtid_mode = ON\nenforce_gtid_consistency = ON<\/code><\/pre>\n<\/div>\n<p><strong>A few things worth knowing here:<\/strong><\/p>\n<ul>\n<li><code class=\"\" data-line=\"\">server-id<\/code> must be unique across every server in your replication topology \u2014 1 for master, 2 for first slave, and so on. Duplicate IDs will silently break replication.<\/li>\n<li><code class=\"\" data-line=\"\">binlog_do_db<\/code> restricts replication to a specific database. Leave it out if you want to replicate everything.<\/li>\n<li><code class=\"\" data-line=\"\">binlog_format = ROW<\/code> is the safest option. <code class=\"\" data-line=\"\">STATEMENT<\/code> mode can cause data drift with non-deterministic functions like <code class=\"\" data-line=\"\">NOW()<\/code> or <code class=\"\" data-line=\"\">UUID()<\/code>.<\/li>\n<li>GTID mode is optional but strongly recommended \u2014 skip the GTID lines if you&#8217;re on a very old setup, but you&#8217;ll need to track binary log positions manually.<\/li>\n<\/ul>\n<p>Restart MySQL to apply the changes:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-2\"><code class=\"\" data-line=\"\">sudo systemctl restart mysql<\/code><\/pre>\n<\/div>\n<h3>Step 2: Create a Replication User on the Master<\/h3>\n<p>Log into MySQL on the master and create a dedicated replication user. Don&#8217;t reuse your application&#8217;s database user for this.<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-3\"><code class=\"\" data-line=\"\">CREATE USER &#039;replicator&#039;@&#039;slave_ip_address&#039; IDENTIFIED WITH mysql_native_password BY &#039;StrongPasswordHere&#039;;\nGRANT REPLICATION SLAVE ON *.* TO &#039;replicator&#039;@&#039;slave_ip_address&#039;;\nFLUSH PRIVILEGES;<\/code><\/pre>\n<\/div>\n<p>Replace <code class=\"\" data-line=\"\">slave_ip_address<\/code> with the actual private IP of your slave server. Never leave example passwords in production \u2014 generate something with <code class=\"\" data-line=\"\">openssl rand -base64 24<\/code> and store it in your password manager.<\/p>\n<h3>Step 3: Record the Master Binary Log Position<\/h3>\n<p>Still on the master, lock the tables briefly and note the current binary log file and position. You need this to tell the slave exactly where to start reading.<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-4\"><code class=\"\" data-line=\"\">FLUSH TABLES WITH READ LOCK;\nSHOW MASTER STATUS;<\/code><\/pre>\n<\/div>\n<p>You&#8217;ll see output like this:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-5\"><code class=\"\" data-line=\"\">+------------------+----------+--------------+------------------+\n| File             | Position | Binlog_Do_DB | Executed_Gtid_Set|\n+------------------+----------+--------------+------------------+\n| mysql-bin.000003 |      154  | your_db      |                  |\n+------------------+----------+--------------+------------------+<\/code><\/pre>\n<\/div>\n<p>Note the <code class=\"\" data-line=\"\">File<\/code> and <code class=\"\" data-line=\"\">Position<\/code> values. Keep this MySQL session open \u2014 closing it will release the lock.<\/p>\n<h3>Step 4: Export the Master Database<\/h3>\n<p>In a second terminal, dump the master database while the lock is held. This ensures the dump matches the log position you just recorded.<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-6\"><code class=\"\" data-line=\"\">mysqldump -u root -p --single-transaction --master-data=2 --databases your_database_name &gt; master_dump.sql<\/code><\/pre>\n<\/div>\n<p>\ud83d\udcdd Note: <code class=\"\" data-line=\"\">--master-data=2<\/code> embeds the binary log position as a comment in the dump file, which is useful for reference. If you&#8217;re using GTID mode, you can also add <code class=\"\" data-line=\"\">--set-gtid-purged=ON<\/code>.<\/p>\n<p>Once the dump is complete, go back to your first terminal and release the lock:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-7\"><code class=\"\" data-line=\"\">UNLOCK TABLES;<\/code><\/pre>\n<\/div>\n<h3>Step 5: Import the Dump on the Slave<\/h3>\n<p>Copy the dump file to the slave server and import it:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-8\"><code class=\"\" data-line=\"\">scp master_dump.sql user@slave_ip:\/tmp\/\nssh user@slave_ip\nmysql -u root -p your_database_name &lt; \/tmp\/master_dump.sql<\/code><\/pre>\n<\/div>\n<h3>Step 6: Configure the Slave Server<\/h3>\n<p>On the slave, edit its MySQL config file with a unique <code class=\"\" data-line=\"\">server-id<\/code> and enable GTID if you&#8217;re using it:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-9\"><code class=\"\" data-line=\"\">[mysqld]\nserver-id = 2\nrelay_log = \/var\/log\/mysql\/mysql-relay-bin.log\ngtid_mode = ON\nenforce_gtid_consistency = ON\nread_only = ON<\/code><\/pre>\n<\/div>\n<p><code class=\"\" data-line=\"\">read_only = ON<\/code> is important. It prevents application code or a runaway script from accidentally writing to the slave and causing data drift. Your replication user is exempt from this restriction, so replication still works.<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-10\"><code class=\"\" data-line=\"\">sudo systemctl restart mysql<\/code><\/pre>\n<\/div>\n<h3>Step 7: Connect the Slave to the Master<\/h3>\n<p>Log into MySQL on the slave and run the <code class=\"\" data-line=\"\">CHANGE MASTER TO<\/code> command with the values you recorded in Step 3:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-11\"><code class=\"\" data-line=\"\">CHANGE MASTER TO\n  MASTER_HOST=&#039;master_ip_address&#039;,\n  MASTER_USER=&#039;replicator&#039;,\n  MASTER_PASSWORD=&#039;StrongPasswordHere&#039;,\n  MASTER_LOG_FILE=&#039;mysql-bin.000003&#039;,\n  MASTER_LOG_POS=154;\n\nSTART SLAVE;<\/code><\/pre>\n<\/div>\n<p>\ud83d\udcdd Note: On MySQL 8.0.23+, <code class=\"\" data-line=\"\">CHANGE MASTER TO<\/code> is deprecated in favour of <code class=\"\" data-line=\"\">CHANGE REPLICATION SOURCE TO<\/code>, and <code class=\"\" data-line=\"\">START SLAVE<\/code> becomes <code class=\"\" data-line=\"\">START REPLICA<\/code>. The old syntax still works but you&#8217;ll see deprecation warnings in the error log.<\/p>\n<h3>Step 8: Verify Replication is Running<\/h3>\n<p>On the slave, check the replication status:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-12\"><code class=\"\" data-line=\"\">SHOW SLAVE STATUSG<\/code><\/pre>\n<\/div>\n<p>Look for these two lines \u2014 both must say <code class=\"\" data-line=\"\">Yes<\/code>:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-13\"><code class=\"\" data-line=\"\">Slave_IO_Running: Yes\nSlave_SQL_Running: Yes<\/code><\/pre>\n<\/div>\n<p>Also check <code class=\"\" data-line=\"\">Seconds_Behind_Master<\/code>. A value of <code class=\"\" data-line=\"\">0<\/code> means the slave is fully caught up. A steadily growing number means the slave can&#8217;t keep up with the master&#8217;s write rate, which usually points to under-resourced hardware.<\/p>\n<p>\u26a0 Warning: If either thread shows <code class=\"\" data-line=\"\">No<\/code>, check the <code class=\"\" data-line=\"\">Last_IO_Error<\/code> and <code class=\"\" data-line=\"\">Last_SQL_Error<\/code> fields in the same output. Those will tell you exactly what went wrong.<\/p>\n<h2>Common Issues and Troubleshooting<\/h2>\n<h3>Slave_IO_Running: Connecting (never reaches Yes)<\/h3>\n<p>This almost always means the slave can&#8217;t reach the master on port 3306. Check your firewall rules on both servers. On Ubuntu with UFW:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-14\"><code class=\"\" data-line=\"\">sudo ufw allow from slave_ip to any port 3306<\/code><\/pre>\n<\/div>\n<p>On AlmaLinux\/RHEL with firewalld:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-15\"><code class=\"\" data-line=\"\">sudo firewall-cmd --permanent --add-rich-rule=&#039;rule family=&quot;ipv4&quot; source address=&quot;slave_ip&quot; port port=3306 protocol=&quot;tcp&quot; accept&#039;\nsudo firewall-cmd --reload<\/code><\/pre>\n<\/div>\n<p>Also confirm MySQL is actually binding on the master&#8217;s network interface and not just <code class=\"\" data-line=\"\">127.0.0.1<\/code>. Check <code class=\"\" data-line=\"\">bind-address<\/code> in <code class=\"\" data-line=\"\">mysqld.cnf<\/code> \u2014 it should be <code class=\"\" data-line=\"\">0.0.0.0<\/code> or the master&#8217;s private IP, not <code class=\"\" data-line=\"\">127.0.0.1<\/code>.<\/p>\n<h3>Error: &#8220;Could not execute Write_rows event on table&#8221; (Error 1062: Duplicate entry)<\/h3>\n<p>This happens when the slave already has a row that the master is trying to insert \u2014 usually because someone wrote directly to the slave, or the initial dump wasn&#8217;t taken while the lock was held. The fix depends on how far the data has diverged. For a small mismatch you can skip the offending event:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-16\"><code class=\"\" data-line=\"\">STOP SLAVE;\nSET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;\nSTART SLAVE;<\/code><\/pre>\n<\/div>\n<p>\u26a0 Warning: Skipping events causes permanent data drift. If you&#8217;re seeing this repeatedly, re-seed the slave from a fresh dump. Don&#8217;t just keep skipping.<\/p>\n<h3>Replication Stopped After MySQL Upgrade<\/h3>\n<p>Upgrading MySQL on the master without upgrading the slave first will break replication, sometimes silently. Always upgrade the slave first, then the master. Check that both report the same major version with <code class=\"\" data-line=\"\">SELECT VERSION();<\/code> before restarting replication.<\/p>\n<h3>Slave Replication Lag Growing Continuously<\/h3>\n<p>A single-threaded slave SQL thread can fall behind on write-heavy masters. Enable parallel replication in the slave&#8217;s config:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-17\"><code class=\"\" data-line=\"\">slave_parallel_workers = 4\nslave_parallel_type = LOGICAL_CLOCK<\/code><\/pre>\n<\/div>\n<p>Restart MySQL on the slave after making the change. <code class=\"\" data-line=\"\">LOGICAL_CLOCK<\/code> is generally safer than <code class=\"\" data-line=\"\">DATABASE<\/code> for most workloads.<\/p>\n<h3>&#8220;Binary logging not possible&#8221; Error After Enabling GTIDs<\/h3>\n<p>This error appears when you enable GTID mode but the existing binary logs contain transactions without GTIDs. You need to let those logs expire (or purge them manually) and then restart replication. Running <code class=\"\" data-line=\"\">RESET MASTER;<\/code> on the master clears the binary logs \u2014 only do this if the slave is already caught up and you&#8217;re prepared to re-seed it.<\/p>\n<h2>FAQ<\/h2>\n<div class=\"ht-faq-section\">\n<h2>Frequently Asked Questions<\/h2>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">Does MySQL replication work in real-time?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>It&#8217;s asynchronous by default, which means there&#8217;s a small delay between a write on the master and it appearing on the slave. In practice this is usually under a second on a well-provisioned setup. If you need guaranteed zero-lag, look into MySQL Group Replication or semi-synchronous replication, both of which have trade-offs in write performance.<\/p>\n<\/div>\n<\/div>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">Can I use a slave server for read queries?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>Yes, and that&#8217;s one of the most common reasons to set up replication. Point your application&#8217;s read queries at the slave&#8217;s IP and writes at the master. Most ORMs and database abstraction layers support read\/write splitting natively. Just account for replication lag \u2014 don&#8217;t run a read immediately after a write and expect the slave to have the new data yet.<\/p>\n<\/div>\n<\/div>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">What happens to replication if the master server restarts?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>The slave will keep trying to reconnect based on the <code class=\"\" data-line=\"\">master_retry_count<\/code> and <code class=\"\" data-line=\"\">master_connect_retry<\/code> settings (default: retry every 60 seconds, up to 86400 times). Once the master is back up, replication resumes from where it left off. No manual intervention needed in most cases.<\/p>\n<\/div>\n<\/div>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">Is MySQL replication the same as a backup?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>No. Replication copies every change to the slave \u2014 including accidental deletes and DROP TABLE statements. If someone wipes a table on the master, that deletion replicates to the slave within seconds. Replication is for availability and read scaling, not for point-in-time recovery. You still need proper backups with tools like mysqldump or Percona XtraBackup.<\/p>\n<\/div>\n<\/div>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">Do both servers need to be with the same hosting provider?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>No, but latency between the master and slave directly affects replication lag. For production setups I&#8217;d recommend keeping both servers in the same datacentre or at least the same region. If you&#8217;re running two VPS nodes, using private networking between them keeps replication traffic off the public internet and avoids bandwidth costs.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>MySQL replication lets you automatically copy data from one server to another in near real-time \u2014 useful for read scaling, failover, and backups. This guide walks through setting up master-slave replication on Linux from scratch, including the gotchas that trip most people up the first time.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[59],"tags":[542,541,544,54,540,467,539,543],"class_list":["post-209","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-binary-logging","tag-database-replication","tag-how-to-set-up-mysql-replication-master-slave-on-linux","tag-linux-server","tag-master-slave-replication","tag-mysql-configuration","tag-mysql-replication","tag-vps-database-setup"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Set Up MySQL Replication (Master-Slave) on Linux<\/title>\n<meta name=\"description\" content=\"Step-by-step guide to configuring MySQL master-slave replication on Linux. Covers server setup, binary logging, GTID, and common replication errors.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Set Up MySQL Replication (Master-Slave) on Linux\" \/>\n<meta property=\"og:description\" content=\"Step-by-step guide to configuring MySQL master-slave replication on Linux. Covers server setup, binary logging, GTID, and common replication errors.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Host And Tech knowledge base\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/stshostandtech\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-02T06:23:31+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@stshostandtech\" \/>\n<meta name=\"twitter:site\" content=\"@stshostandtech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/person\\\/b6fa79c48ddaba71af32e395c5b017ee\"},\"headline\":\"How to Set Up MySQL Replication (Master-Slave) on Linux\",\"datePublished\":\"2026-06-02T06:23:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/\"},\"wordCount\":1449,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\"},\"keywords\":[\"binary logging\",\"database replication\",\"How to Set Up MySQL Replication (Master-Slave) on Linux\",\"Linux server\",\"master-slave replication\",\"MySQL configuration\",\"mysql replication\",\"vps database setup\"],\"articleSection\":[\"MySQL &amp; MariaDB\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/\",\"name\":\"How to Set Up MySQL Replication (Master-Slave) on Linux\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#website\"},\"datePublished\":\"2026-06-02T06:23:31+00:00\",\"description\":\"Step-by-step guide to configuring MySQL master-slave replication on Linux. Covers server setup, binary logging, GTID, and common replication errors.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/mysql\\\/how-to-set-up-mysql-replication-master-slave-linux\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Set Up MySQL Replication (Master-Slave) on Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\",\"name\":\"Host And Tech knowledge base\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\",\"name\":\"Host And Tech knowledge base\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/wp-content\\\/uploads\\\/2026\\\/05\\\/logo-dark.png\",\"contentUrl\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/wp-content\\\/uploads\\\/2026\\\/05\\\/logo-dark.png\",\"width\":1134,\"height\":395,\"caption\":\"Host And Tech knowledge base\"},\"image\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/stshostandtech\",\"https:\\\/\\\/x.com\\\/stshostandtech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/person\\\/b6fa79c48ddaba71af32e395c5b017ee\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/hostandtech.com\\\/kb\"],\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/author\\\/admin_fjj7qydm\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Set Up MySQL Replication (Master-Slave) on Linux","description":"Step-by-step guide to configuring MySQL master-slave replication on Linux. Covers server setup, binary logging, GTID, and common replication errors.","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:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/","og_locale":"en_US","og_type":"article","og_title":"How to Set Up MySQL Replication (Master-Slave) on Linux","og_description":"Step-by-step guide to configuring MySQL master-slave replication on Linux. Covers server setup, binary logging, GTID, and common replication errors.","og_url":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/","og_site_name":"Host And Tech knowledge base","article_publisher":"https:\/\/www.facebook.com\/stshostandtech","article_published_time":"2026-06-02T06:23:31+00:00","author":"admin","twitter_card":"summary_large_image","twitter_creator":"@stshostandtech","twitter_site":"@stshostandtech","twitter_misc":{"Written by":"admin","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/#article","isPartOf":{"@id":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/"},"author":{"name":"admin","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/person\/b6fa79c48ddaba71af32e395c5b017ee"},"headline":"How to Set Up MySQL Replication (Master-Slave) on Linux","datePublished":"2026-06-02T06:23:31+00:00","mainEntityOfPage":{"@id":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/"},"wordCount":1449,"commentCount":0,"publisher":{"@id":"https:\/\/hostandtech.com\/kb\/#organization"},"keywords":["binary logging","database replication","How to Set Up MySQL Replication (Master-Slave) on Linux","Linux server","master-slave replication","MySQL configuration","mysql replication","vps database setup"],"articleSection":["MySQL &amp; MariaDB"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/","url":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/","name":"How to Set Up MySQL Replication (Master-Slave) on Linux","isPartOf":{"@id":"https:\/\/hostandtech.com\/kb\/#website"},"datePublished":"2026-06-02T06:23:31+00:00","description":"Step-by-step guide to configuring MySQL master-slave replication on Linux. Covers server setup, binary logging, GTID, and common replication errors.","breadcrumb":{"@id":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/hostandtech.com\/kb\/mysql\/how-to-set-up-mysql-replication-master-slave-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/hostandtech.com\/kb\/"},{"@type":"ListItem","position":2,"name":"How to Set Up MySQL Replication (Master-Slave) on Linux"}]},{"@type":"WebSite","@id":"https:\/\/hostandtech.com\/kb\/#website","url":"https:\/\/hostandtech.com\/kb\/","name":"Host And Tech knowledge base","description":"","publisher":{"@id":"https:\/\/hostandtech.com\/kb\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/hostandtech.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/hostandtech.com\/kb\/#organization","name":"Host And Tech knowledge base","url":"https:\/\/hostandtech.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/hostandtech.com\/kb\/wp-content\/uploads\/2026\/05\/logo-dark.png","contentUrl":"https:\/\/hostandtech.com\/kb\/wp-content\/uploads\/2026\/05\/logo-dark.png","width":1134,"height":395,"caption":"Host And Tech knowledge base"},"image":{"@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/stshostandtech","https:\/\/x.com\/stshostandtech"]},{"@type":"Person","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/person\/b6fa79c48ddaba71af32e395c5b017ee","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/hostandtech.com\/kb"],"url":"https:\/\/hostandtech.com\/kb\/author\/admin_fjj7qydm\/"}]}},"_links":{"self":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":0,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"wp:attachment":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}