1、设置master mysql的/etc/my.cnf
[mysqld]log-bin=mysql-binserver-id=1
在master上创建一个复制用户
mysql> CREATE USER 'repl'@'%' IDENTIFIED BY 'slavepass';mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
锁定表:
mysql> FLUSH TABLES WITH READ LOCK;
查看master状态
mysql > SHOW MASTER STATUS;
创建一个数据快照
shell> mysqldump -uroot -p1234567 --all-databases --master-data > dbdump.db
2、设置salve mysql
在master上解锁表
mysql> UNLOCK TABLES;
设置salve mysql的/etc/my.cnf
[mysqld]
server-id=2
在salve上设置Master Configuration
mysql> CHANGE MASTER TO-> MASTER_HOST='master_host_name',-> MASTER_USER='replication_user_name',-> MASTER_PASSWORD='replication_password',-> MASTER_LOG_FILE='recorded_log_file_name',-> MASTER_LOG_POS=recorded_log_position;