主节点配置
step1 mysqld.cnf 中指定log-bin 文件名 server-id 默认为1 (从节点不能与之重复)
step2 创建一个用来同步的账号
create user 'repl'@'%' identified by '123456';
grant replication slave on *.* to 'repl'@'%';
step3 主节点锁表
flush tables with read lock;
step4 记住log-bin的位置 show master status
step5 从节点备份好数据后 主节点解锁 unlock tables;
从节点配置
step1 mysqld.cnf 中指定 server-id 为2 不和主节点重复
step2 备份主节点数据
mysqldump --all-databases --master-data > dbdump.db -h 主节点ip -P 3306 -u root -p
step3 导入数据
mysql < dbdump.db
step4 配置主节点信息
change to master to
master_host='主节点ip',
master_user='repl',
master_password='123456',
master_log_file='log-bin文件名',
master_log_pos='log-bin position';