{"id":1031,"date":"2026-09-01T23:33:43","date_gmt":"2026-09-01T23:33:43","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1031"},"modified":"2026-09-01T23:33:43","modified_gmt":"2026-09-01T23:33:43","slug":"vps-database-replication-mysql-master-slave","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/","title":{"rendered":"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Database replication is often associated with multi-server architectures, but you can run a fully functional MySQL master-slave setup on a single VPS. Why would you do that? For backups without locking production tables, running analytics queries against a read replica, testing failover scenarios, or simply learning replication before moving to a multi-node cluster. This tutorial walks through a practical single-VPS master-slave configuration using MySQL 8 on Ubuntu.<\/p>\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n<ul class=\"wp-block-list\"><li>A VPS running Ubuntu 22.04 or later with at least 2 GB RAM and 10 GB free disk space.<\/li><li>MySQL 8 installed (<code>sudo apt install mysql-server<\/code>).<\/li><li>Root or sudo access.<\/li><li>Basic familiarity with the MySQL command line.<\/li><\/ul>\n\n<p class=\"wp-block-paragraph\">If you need a VPS for this setup, consider the plans at <a href=\"https:\/\/virtualserversvps.com\">virtualserversvps.com<\/a>\u2014a 2 GB RAM instance is sufficient for learning and light workloads.<\/p>\n\n<h2 class=\"wp-block-heading\">Step 1: Install and Configure MySQL<\/h2>\n\n<p class=\"wp-block-paragraph\">If MySQL is not already running, install it and secure the installation:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install mysql-server -y\nsudo mysql_secure_installation<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Follow the prompts to set a root password and remove anonymous users. Then edit the MySQL configuration file:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Find the <code>[mysqld]<\/code> section and add or modify these lines:<\/p>\n\n<pre class=\"wp-block-code\"><code>server-id = 1\nlog_bin = \/var\/log\/mysql\/mysql-bin.log\nbinlog_do_db = your_database_name\nbind-address = 127.0.0.1<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Replace <code>your_database_name<\/code> with the actual database you want to replicate. The <code>bind-address<\/code> stays local because both master and slave run on the same host. Restart MySQL:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart mysql<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">Step 2: Create a Replication User<\/h2>\n\n<p class=\"wp-block-paragraph\">Log into MySQL as root:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo mysql -u root -p<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Create a user specifically for replication:<\/p>\n\n<pre class=\"wp-block-code\"><code>CREATE USER 'replicator'@'127.0.0.1' IDENTIFIED BY 'strong_password';\nGRANT REPLICATION SLAVE ON *.* TO 'replicator'@'127.0.0.1';\nFLUSH PRIVILEGES;<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Note the master status\u2014you will need these coordinates for the slave:<\/p>\n\n<pre class=\"wp-block-code\"><code>SHOW MASTER STATUS;<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Write down the File and Position values from the output.<\/p>\n\n<h2 class=\"wp-block-heading\">Step 3: Configure the Slave Instance<\/h2>\n\n<p class=\"wp-block-paragraph\">On a single VPS, the slave runs as a separate MySQL instance on a different port. The cleanest approach is to use MySQL&#8217;s multi-source or run a second MySQL process with a separate data directory and config file. For simplicity, we will use Docker to run the slave instance on port 3307 while the master runs natively on 3306.<\/p>\n\n<p class=\"wp-block-paragraph\">Install Docker if not already present:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo apt install docker.io -y\nsudo systemctl start docker<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Run the slave container:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo docker run -d \\\n  --name mysql-slave \\\n  -e MYSQL_ROOT_PASSWORD=slave_root_pass \\\n  -p 127.0.0.1:3307:3306 \\\n  mysql:8.0<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Now configure the slave to connect to the master. Connect to the slave container:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo docker exec -it mysql-slave mysql -u root -p<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Run the following, replacing the MASTER_LOG_FILE and MASTER_LOG_POS with the values from Step 2:<\/p>\n\n<pre class=\"wp-block-code\"><code>CHANGE MASTER TO\n  MASTER_HOST='127.0.0.1',\n  MASTER_PORT=3306,\n  MASTER_USER='replicator',\n  MASTER_PASSWORD='strong_password',\n  MASTER_LOG_FILE='mysql-bin.000001',\n  MASTER_LOG_POS=1234;\n\nSTART SLAVE;<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Check the slave status:<\/p>\n\n<pre class=\"wp-block-code\"><code>SHOW SLAVE STATUS\\G<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Look for <code>Slave_IO_Running: Yes<\/code> and <code>Slave_SQL_Running: Yes<\/code>. If either says <code>No<\/code>, check the <code>Last_IO_Error<\/code> or <code>Last_SQL_Error<\/code> field for details.<\/p>\n\n<h2 class=\"wp-block-heading\">Step 4: Test Replication<\/h2>\n\n<p class=\"wp-block-paragraph\">On the master (port 3306), create a test database and a table:<\/p>\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE test_repl;\nUSE test_repl;\nCREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100));\nINSERT INTO users VALUES (1, 'Alice');<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">On the slave (port 3307), verify the data arrived:<\/p>\n\n<pre class=\"wp-block-code\"><code>USE test_repl;\nSELECT * FROM users;<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">You should see the row with Alice. If you do, replication is working. You can now use the slave for read-only queries, backups, or testing without affecting the master.<\/p>\n\n<h2 class=\"wp-block-heading\">Use Cases for Single-VPS Replication<\/h2>\n\n<ul class=\"wp-block-list\"><li><strong>Lock-free backups<\/strong> \u2014 Run <code>mysqldump<\/code> against the slave while the master handles production traffic.<\/li><li><strong>Analytics<\/strong> \u2014 Point reporting tools at the slave so heavy queries do not slow the main application.<\/li><li><strong>Failover practice<\/strong> \u2014 Stop the slave, promote it, then reattach\u2014learn the mechanics without risking a real cluster.<\/li><li><strong>Staging schema changes<\/strong> \u2014 Test ALTER TABLE on the slave before applying to the master.<\/li><\/ul>\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n<p class=\"wp-block-paragraph\">A single-VPS MySQL master-slave setup is a low-risk way to learn database replication, improve backup workflows, and isolate read-heavy workloads. Once you outgrow one server, the same configuration scales directly to a multi-node cluster across multiple VPS instances. For more VPS database tutorials, visit <a href=\"https:\/\/virtualserversvps.com\">virtualserversvps.com<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Database replication is often associated with multi-server architectures, but you can run a fully functional MySQL master-slave setup on a single VPS. Why would you do that? For backups without&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1031","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS\" \/>\n<meta property=\"og:description\" content=\"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-01T23:33:43+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/\",\"name\":\"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-09-01T23:33:43+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS - Virtual Servers VPS Blog","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:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/","og_locale":"en_US","og_type":"article","og_title":"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS","og_description":"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS","og_url":"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-09-01T23:33:43+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/","url":"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/","name":"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-09-01T23:33:43+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/vps-database-replication-mysql-master-slave\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"VPS Database Replication: Setting Up MySQL Master-Slave on a Single VPS"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1031"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1031\/revisions"}],"predecessor-version":[{"id":1032,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1031\/revisions\/1032"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}