1.创建用户:
grant replication slave,replication client on *.* to repl@'192.168.1.%' IDENTIFIED By 'p4ssword';
2.修改 my.cnf里面增加
log_bin=mysql-bin
server_id =10#这个要唯一,可以用IP地址后8位
3.为了确认二进制日志文件是否已经在主库上创建,使用show master status 命令
4.备库上需要在my.cnf 中增加类似的
blg_bin = mysql-bin
server_id = 2
relay_log=/var/bin/mysql/mysql-relay-bin
log_slave_updates=1
read_only = 1
5.启动复制
使用change master to 语句
mysql > change master to master_host='server1',
master_user='repl',
master_password='p4ssword',
master_log_file='mysql-bin.000001',
master_log_pos=0;
========================================
master_log_pos 参数设置为0,因为要从日志的开头读起
========================================
可以通过 show slave satatus 语句来检查复制是否正确执行
=================================
开始复制:
mysql> start slave;
==========================
show slave status\G
======================
mysql> show processlist\G