centos mysql master slave replication Settings detail
- 2020-06-03 08:38:06
- OfStack
Installation environment :centos 5.4
mysql version: mysql 5.1.xx is installed directly with rpm
Required software: xtrabackup 1.2.22 shall be installed directly by rpm
1. Master:/etc/my.cnf
[mysqld]
server-id = 1
log-bin innodb_flush_log_at_trx_commit=1
sync_binlog=1
datadir=/var/lib/mysql
character-set-server=utf8
init_connect='SET NAMES utf8'
The default character set is utf8, and this configuration can be selected as the case may be.
2. Slave:/etc/my.cnf
[mysqld]
server-id=2
datadir=/var/lib/mysql
character-set-server=utf8
init_connect='SET NAMES utf8'
3. Master: Set slave user permissions for synchronization in master database
GRANT REPLICATION SLAVE ON *.* TO '<slave_username>'@'<slave_ip>' IDENTIFIED BY '<slave_password>';
4. Master: Export data to slave
Using xtrabackup to back up mysql has the advantage that the lock table time in master is short, it can be used in a real production environment, and xtrabackup automatically records the location of synchronization log files.
sudo innobackupex-1.5.1 --stream=tar /tmp/ | ssh <slave_host> "mkdir /tmp/db; tar xfi - -C /tmp/db/"
This step exports and compresses the entire master data including the table structure to slave and unzips it to the /tmp/db directory of slave.
5. Slave: Import data to slave
innobackupex-1.5.1 --apply-log /tmp/db innobackupex-1.5.1 --copy-back /tmp/db chown -R mysql.mysql /var/lib/mysql/*
Slave: Start synchronizing data
View/var/lib/mysql/xtrabackup_binlog_info, get the log file and position.
CHANGE MASTER TO MASTER_HOST='<master_host>', MASTER_USER='<slave_username>', MASTER_PASSWORD='<slave_password>', MASTER_LOG_FILE='<see xtrabackup_binlog_info>', MASTER_LOG_POS=<see xtrabackup_binlog_info>; START SLAVE;