mysql 设置主从服务器步骤:
1. grant replication slave on *.* to @ identified by ' ';
2. 开启binlog log-bin =/path
server-id = 奇数(master) 偶数(slave)
3. flush tables with read lock; (master)
show master status; (master 二进制日志名file 和偏移量postion (master)
4. 备份数据
5. unlock tables;
6. server-id = 2 (slave)
7. mysqld_safe --skip-slave-start & (slave, 不会立即从主数据库复制
8. chance master to master_host =
master_user = "replication_user_name"
master_ port =
master_password =
master_log_file =
master_log_pos = ;
9. start slave
10. show processlist\G (slave)
主要复制启动选项:
1. master_connect_retry = 秒
2. master_retry_count = 次数
3. read-only 只允许超级用户的更新操作
4. relay_log_file 开始复制是执行从服务器的中继日志名
5. relay_log_pos 开始复制是执行从服务器的中继日志位置
查看从服务器信息:
1. show slave status\; 可以得到信息如:connect_retry
read_master_log_pos 从主二进制日志中有I/O线程读的当前位置
relay_log_file 当前中继日志文件
relay_log_pos 从中继日志文件中读的当前事件位置
进程:1. Slave_IO_Running 从服务器从主上读取 binlog日志,并写入从的中继日志中
2. Slave_SQL_Running 读取并且执行中继日志中binlog, 执行完sql线程删除这个日志
3. 只要其中一个进程的状态是NO, 则表示复制进程停止。
2. show slave hosts; 用于显示当前使用主服务器注册的复制从属服务器的清单。
查看主服务器信息:
1. show master status\G;
2。进程:I/O线程 二进制日志转储线程
当主服务器出现故障,需要切换从为主
slave
1. stop slave IO_THREAD;
2. show processlist \G; Has read all relay log 表示所有relay log 中继日志已经执行完
3. stop slave
4. reset master
grant replication slave on *.* to identified by ' ';
停止别的slave
5. stop slave
6. chance mastet to master_host = ' ';
7. start slave
从到主的服务器信息文件
8. 删除这两个信息档 master.info relay-log.info
当主从不同步,强制同步:
1. master:
1.1 flush tables with read lock
1.2 show master status
2. slave : select master_pos_wait('bin.000000','98');
阅读(358) | 评论(0) | 转发(0) |