Installation environment: centos 5.4
Mysql version: mysql 5.1.xx is directly installed using rpm
Required Software: xtrabackup 1.2.22 directly installed with rpm
1. Master:/etc/my. cnf
Copy codeThe Code is as follows:
[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'
If the default character set is set to utf8, you can choose this configuration as needed.
2. Slave:/etc/my. cnf
Copy codeThe Code is as follows:
[Mysqld]
Server-id = 2
Datadir =/var/lib/mysql
Character-set-server = utf8
Init_connect = 'set NAMES utf8'
3. Master: Set the slave user permissions for synchronization in the master database.
Copy codeThe Code is as follows:
Grant replication slave on *. * TO '<slave_username>' @ '<slave_ip> 'identified BY' <slave_password> ';
4. Master: export data to slave
Xtrabackup is used to back up mysql. The advantage is that the lock table time on the master node is very short and can be used in the actual production environment. xtrabackup automatically records the location of the synchronization log file.
Copy codeThe Code is as follows:
Sudo innobackupex-1.5.1 -- stream = tar/tmp/| ssh <slave_host> "mkdir/tmp/db; tar xfi--C/tmp/db /"
In this step, the master data, including the entire table structure, is exported, compressed, copied to slave, and decompressed to the/tmp/db directory of slave.
5. Slave: import data to slave
Copy codeThe Code is as follows:
Innobackupex-1.5.1 -- apply-log/tmp/db innobackupex-1.5.1 -- copy-back/tmp/db chown-R mysql. mysql/var/lib/mysql /*
6. Slave: Start Data Synchronization
View/var/lib/mysql/xtrabackup_binlog_info to obtain the log file and position.
Copy codeThe Code is as follows:
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;