Mysql Master/Slave的配置

来源:互联网 发布:云帆搜索软件 编辑:程序博客网 时间:2024/04/28 03:15

 MYSQL数据同步备份
A服务器: 192.168.18.112 主服务器master
B服务器: 192.168.18.113 副服务器slave

A服务器设置
#mysql –u root –p
 mysql>grant replication slave,replication client on *.* to test@192.168.18.113
       identified by '111111';
 mysql>flush tables with read lock;
 mysql>show master status;(读取相关的二进制文件和偏移量,记录下Position 和 File)
       +—————————+————— +———————+——————+———+
       | File            | Position | Binlog_Do_DB | Binlog_Ignore_DB |
       +—————————+————— +———————+——————————+
       | mysql-bin.000012| 106      | db1          |mysql           |
       +—————————+————— +———————+——————————+
 mysql>unlock tables;
 mysql>exit
上面是Master开放一个账号test 密码111111 给IP:192.168.18.113 有档案处理的权限

设定/etc/my.cnf
在[mysqld]区段内加入参数
  log-bin=mysql-bin
  server-id=1
  binlog_do_db = myw(要同步的数据库)
  binlog_ignore_db = mysql,test,information_schema (不需要同步的库)
  default-character-set=utf8 (为了避免数据库编码不一致导致无法同步,统一规定编码)
重启A服务器mysql

B服务器设置
#mysql –u root –p
 mysql>stop slave;
 mysql>change master to
     ->master_host='192.168.18.112',
     ->master_user='test',   
     ->master_password='111111',
     ->master_log_file='mysql-bin.000012',
     ->master_log_pos=106;
 mysql>start slave;
 mysql>exit
设定/etc/my.cnf
在[mysqld]区段加入
  server-id = 2 (如果还有slave用户,他们的ID也随之增加,如server-id=3)
  master-host = 192.168.18.112
  master-user = root
  master-password = 111111
  replicate-do-db = myw
  log-warnings
  master-port=3306
  master-connect-retry = 60
  default-character-set=utf8(为了避免数据库编码不一致导致无法同步,统一规定编码)
在[mysql]区段加入
  default-character-set=utf8 (为了避免数据库编码不一致导致无法同步,统一规定编码)
重启B服务器的MYSQL
#mysql –u root –p
>show slavestatus\G (查看复制状态,状态信息中Slave_IO_Running和Slave_SQL_Running应该都是yes)

change master to Master_Log_File='mysql-bin.000001',Master_Log_Pos=106;

原创粉丝点击