Databases 9 min read

How to Deploy Multiple MySQL Instances on a Single Server: Step‑by‑Step Guide

This article explains the concept, use cases, benefits, and challenges of running multiple MySQL instances on one machine, then provides a detailed, command‑line walkthrough—including environment preparation, compilation, configuration files, startup, security measures, and management scripts—to help you set up and manage multi‑instance MySQL deployments.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Deploy Multiple MySQL Instances on a Single Server: Step‑by‑Step Guide

Basic Concepts

MySQL multi‑instance means running several MySQL server processes on different ports on the same machine, sharing the same installation but using separate configuration files, data directories, and resources.

Use Cases

Adopt a pseudo‑distributed architecture during early project stages.

Avoid MySQL’s limitation on SMP architectures by binding instances to specific CPUs.

Improve recovery speed of replica slaves by deploying multiple instances on one server.

Provide hot standby for critical data in a separate data center when multi‑master replication is unavailable.

Separate databases per game server (MMO/MMORPG, Web Game) to reduce maintenance errors.

Benefits and Issues

Better utilization of server resources when capacity is idle.

Potential resource contention (memory, CPU, NUMA, disk I/O, network interrupts) requiring careful binding and configuration.

Installation Steps

Synchronize time and install required packages (epel, ntp, autoconf, automake, zlib, libxml, ncurses‑devel, libgcrypt, libtool, openssl, cmake).

Create mysql group and user, prepare data directories (e.g., /data/{3306,3307,3308}).

Compile MySQL from source with appropriate CMake options.

Initialize each instance with scripts/mysql_install_db specifying different datadirs.

Generate a multi‑instance configuration file using mysqld_multi --example > /data/multi.cnf and edit it to define [mysqld1], [mysqld2], [mysqld3] sections (ports 3306‑3308, sockets, pid files, datadirs).

Start instances with mysqld_multi --defaults-file=/data/multi.cnf start 1,2,3 and verify listening ports.

Log in via socket, perform basic security tasks (drop test database, clean mysql.user entries, set root password).

Stop instances using mysqld_multi --defaults-file=/data/multi.cnf stop 1,2,3 or mysqladmin.

Optional: use the provided Bash management script to start, stop, report, or restart instances.

For an additional instance on port 3309, create its data directory, initialize it, and add a [mysqld] section to a separate configuration file.

Conclusion

The multi‑instance setup is straightforward and does not require advanced tricks; it offers flexibility to choose between a single configuration file or multiple files, and can be refined further as needed.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseDeploymentConfigurationLinuxmysqlMulti-Instance
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.