realtime MySQL mirror on the same server use stored on another disk partition MySQL replication

  • Author: Admin
  • Published On: 3/16/2026
  • Category: editor
real-time MySQL mirror on the same server but stored on another disk partition MySQL replication (master → slave)
Architecture
Server
│
ā”œā”€ā”€ MySQL Instance 1 (MASTER)
│     port: 3306
│     datadir: /var/lib/mysql
│
└── MySQL Instance 2 (SLAVE)
      port: 3307
      datadir: /mnt/mysql_mirror
	  
Your second partition might be something like:
/dev/sdb1 → /mnt/mysql_mirror
Create the Mirror Data Directory
sudo mkdir -p /mnt/mysql_mirror
sudo chown -R mysql:mysql /mnt/mysql_mirror
Initialize the database:
mysqld --initialize-insecure --datadir=/mnt/mysql_mirror
Create Second MySQL Configuration Create a new config file:
/etc/mysql/my-slave.cnf
Example:
[mysqld]
server-id=2
port=3307
datadir=/mnt/mysql_mirror
socket=/var/run/mysqld/mysqld2.sock
relay-log=relay-bin
log_bin=mysql-bin
read_only=1
Start the Second MySQL Instance
mysqld_safe --defaults-file=/etc/mysql/my-slave.cnf &
Check:
mysql -u root -S /var/run/mysqld/mysqld2.sock
Configure Master (Main MySQL) Edit main config (my.cnf):
[mysqld]
server-id=1
log_bin=mysql-bin
Restart MySQL. Create replication user:
CREATE USER 'replica'@'127.0.0.1' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON . TO 'replica'@'127.0.0.1';
FLUSH PRIVILEGES;
Get Master Log Position On the master:
SHOW MASTER STATUS;
Example:
File: mysql-bin.000001
Position: 120
Configure Slave Connect to the second instance:
mysql -u root -S /var/run/mysqld/mysqld2.sock
Run:
CHANGE MASTER TO
MASTER_HOST='127.0.0.1',
MASTER_PORT=3306,
MASTER_USER='replica',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=120;
Start replication:
START SLAVE;
Check status:
SHOW SLAVE STATUS\G
You should see:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Result
Partition 1 (/var/lib/mysql)
     ↓
MySQL MASTER (3306)
     ↓ replication
MySQL SLAVE (3307)
     ↓
Partition 2 (/mnt/mysql_mirror)
Advantages āœ… Real-time mirror āœ… Safe (transaction-based) āœ… No file corruption āœ… Can promote mirror if main DB fails
  • Share On: