Mysql主从复制
系统环境
系统版本:Centos6.4-x86.64
软件环境
mysql-5.5.27
环境
角色 IP地址
Mysql-Master 192.168.1.10(Mysql对外服务IP)
192.168.1.11(主从同步IP)
MySql-Slave 192.168.1.20(slave对外服务IP)
192.168.1.22(主从同步IP)
主库授权密码 tongda
--------------------------------------------------------
1.系统环境准备
关闭防火墙和SELINUX
2.主库配置步骤
#############################
vim /etc/my.cnf
#########my.cnf################
log-bin=master-bin (开启mysql-binlog日志)
server-id=10 (指定mysql-master-id)
###############################
[root@mysql~]# service mysql restart
#########登录mysql##############
mysql> grant replication slave on *.* to slave22@‘192.168.1.22‘ identified by ‘tongda‘;
mysql> flush privileges;
mysql> reset master
mysql> show master status;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| my-bak.000004 | 2382 | | mysql,mysql |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)
2.从库配置步骤
#############################
vim /etc/my.cnf
#########my.cnf###############
server-id=20 (指定mysql-slave-id)
##########登录mysql############
mysql> change master to master_host=‘192.168.1.10‘, master_user=‘slave20‘, master_password=‘tongdal‘, master_log_file=‘mysql-bin.000004‘, master_log_pos=2382;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.30
Master_User: slave
Master_Port: 3336
Connect_Retry: 60
Master_Log_File: my-bak.000004
Read_Master_Log_Pos: 2382
Relay_Log_File: ipsan-relay-bin.000013
Relay_Log_Pos: 2525
Relay_Master_Log_File: my-bak.000004
Slave_IO_Running: Yes//从主服务器读binlog,存放在本机 Slave_SQL_Running: Yes//读本地mysqld-relay-bin(中继日志),写入本机mysql
#################################################################
注释:
master_log_file=‘mysql-bin.*‘, master_log_pos=*;
binlog值和pos值具体需要查看主库状态获取
mysql> show master status; 查看出库状态
#####################################################################
mysql主从机器对外服务IP和主从同步IP可为一个网卡或两个网卡,推荐绑定在两个网卡并且配置其他网段IP地址
本文出自 “悬剑” 博客,请务必保留此出处http://sublime.blog.51cto.com/8856101/1545512
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。