Installation Environment
CentOS 5.4
MySQL 5.1.xx with rpm direct installation
Xtrabackup 1.2.22 with RPM direct installation
Copy Code code 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 '
Set the default character set for UTF8, you can choose this configuration according to the actual situation.
2. slave:/etc/my.cnf
Copy Code code 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 rights to sync in the master database
Copy Code code as follows:
GRANT REPLICATION SLAVE on *.*
To ' <slave_username> ' @ ' <slave_ip> '
Identified by ' <slave_password> ';
4. Master: Export data to Slave
The advantage of using Xtrabackup to back up MySQL is that the master has a very short lock schedule, is available in the actual production environment, and Xtrabackup automatically records the location of the synchronization log files.
Copy Code code as follows:
sudo innobackupex-1.5.1--stream=tar/tmp/| SSH <slave_host> "mkdir/tmp/db; Tar Xfi--c/tmp/db/"
This step will take Master's data, including the table structure, to the entire export and compression copy to the slave, while extracting the slave/tmp/db directory.
5. Slave: Import data to Slave
Copy Code code 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 synchronizing Data
View/var/lib/mysql/xtrabackup_binlog_info, get log files, and position.
Copy Code code 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;
Original source http://www.ooso.net/archives/547