1. 建立replication 用户(master, optional):
CREATE USER 'user_name'@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
2. 在master server中配置server-id, 启用binary-log 修改/etc/mysql/my.cnf文件:
在[mysqld]下增加或修改:
server-id = 1(非0)
log-bin = mysql-bin(作为前缀,如果原来就有,则可使用默认)
在master 上执行:
a. FLUSH TABLES WITH READ LOCK;
b. SHOW MASTER STATUS; --> 记住file和position,后面要用
3. dump数据
a. FLUSH TABLES WITH READ LOCK;
b. mysqldump -ucootek -pcootek oceanus --lock-all-tables > data.db
c. UNLOCK TABLES;
4. 配置slave:
server-id = 2(唯一)
5. 启动mysql, 加入--skip-slave-start选项
sudo /etc/init.d/mysql start --skip-slave-start
6. 导入数据
mysql -ucootek -pcootek < data.db
7. 在slave中执行:
change master to
--> master_host = 'host',
--> master_user = 'user_name',
--> master_password = 'password',
--> master_log_file = 'file',
--> master_log_pos = position;
8. 启动slave:
START SLAVE;
1. 建立replication 用户(master, optional):CREATE USER 'user_name'@'%' IDENTIFIED BY 'password';GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';2. 在master server中配置server-id, 启用binary-log 修改/etc/mysql/my.