mysql 主从复制

主库服务器环境:

操作系统:Centos6.5

数据库:Mysql5.5

IP: 111.111.111.111


从库服务器环境:

操作系统:Centos6.5

数据库:Mysql5.5

IP:222.222.222.222


1、主库创建同步用户

[plain] view plain copy
  1. mysql> grant replication slave, replication client on *.* to backup@'222.222.222.222' identified by '密码';  


2、主库配置

[plain] view plain copy
  1. log-bin=mysql-bin  
  2. binlog_format=mixed  
  3. server-id = 1  

配置后重启MySQL


3、从库配置

[html] view plain copy
  1. log-bin=mysql-bin  
  2. binlog_format=mixed  
  3. server-id = 2  
  4. relay_log = /var/lib/mysql/mysql-relay-bin  #mysql数据目录位置,如/data/mysqldata/relay.log  
  5. log_slave_updates = 1  
  6. read_only = 1    #从库是否可写  
配置后重启mysql


4、从库启动slave

[plain] view plain copy
  1. mysql> change master to master_host='192.168.1.201',  
  2. master_user='repl',  
  3. master_password='100301',  
  4. master_log_file='mysql-bin.000001',  
  5. master_log_pos=0;  

从库开启同步

[plain] view plain copy
  1. mysql> start slave;  




[测试]从服务器连接主库:

[plain] view plain copy
  1. mysql -h222.222.222.222 -ubackup -p  
posted @ 2017-08-27 15:34  海尚书  阅读(99)  评论(0)    收藏  举报