How to quickly configure mysql master-slave synchronization in centos

Source: Internet
Author: User

Installation environment
Centos 1, 5.4
Mysql 5.1.xx is directly installed using rpm
Xtrabackup 1.2.22 directly installed with 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, you can select this configuration as needed.

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 the slave user permissions for synchronization in the master database.
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.

Sudo innobackupex-1.5.1 -- stream = tar/tmp/| ssh <slave_host> "mkdir/tmp/db; tar xfi--C/tmp/db/"this step will export and compress the master data, including the table structure, and copy the data to slave. At the same time, decompress the data 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 /*

6. Slave: Start Data Synchronization
View/var/lib/mysql/xtrabackup_binlog_info to obtain 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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.