mysql 主从搭建步骤

mysql 主从搭建步骤
1:主库开启master端bin-log
2:主库创建备份用户
3:主库全备
4:从库导入全备数据
5:从库修改change master to信息
6:从库slave start
 
 
0 确认server_id和binlog
vim my.cnf
log-bin=/data/3306/mysql-bin #master开启binlog
server_id=1 #主从必须不同

1 master上创建用户
grant replication slave on *.* to 'rep'@'192.168.1.%' identified by '123456';
flush privileges;

2 锁表全备
flush tables with read lock;
show master status;

mysqldump -uroot -pxxxx -A -B --events --single-transaction --master-data=1|gzip > full.sql.gz

unlock table;

3 从库导入备份
gzip -d full.sql.gz
mysql -uroot -pxxxx < full.sql

4 配置同步
change master to
master_host='xxxx',
master_port=3306,
master_user='rep',
master_password='xxxxxxx'


5 从库启用同步
start salve
show slave status\G;





posted @ 2016-07-25 14:24  杨小愚  阅读(679)  评论(0编辑  收藏  举报