Home > Database > Mysql Tutorial > centos下mysql主从同步快速设置步骤分享

centos下mysql主从同步快速设置步骤分享

WBOY
Release: 2016-06-07 18:07:40
Original
1120 people have browsed it

记录一个比较简便的mysql的主从同步设置步骤,方便日后使用。

安装环境
centos 5.4
mysql 5.1.xx 采用rpm直接安装
xtrabackup 1.2.22 采用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'设定了默认字符集为utf8,可以按实际情况取舍这段配置。

2. Slave:/etc/my.cnf
[mysqld] server-id=2 datadir=/var/lib/mysql character-set-server=utf8 init_connect='SET NAMES utf8'

3. Master:在master数据库设置用来同步的slave用户权限
GRANT REPLICATION SLAVE ON *.* TO ''@'' IDENTIFIED BY '';

4. Master:导出数据到slave
采用xtrabackup来备份mysql,好处是在master的锁表时间很短,在实际的生产环境也可以使用,并且xtrabackup会自动记录同步日志文件的位置。

sudo innobackupex-1.5.1 --stream=tar /tmp/ | ssh "mkdir /tmp/db; tar xfi - -C /tmp/db/"这个步骤会把master的数据包括表结构整个导出并压缩复制给slave,同时解压到slave的/tmp/db目录下。

5. Slave:导入数据到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:开始同步数据
查看/var/lib/mysql/xtrabackup_binlog_info,获得日志文件以及position。

CHANGE MASTER TO MASTER_HOST='', MASTER_USER='', MASTER_PASSWORD='', MASTER_LOG_FILE='', MASTER_LOG_POS=; START SLAVE;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template