zoukankan      html  css  js  c++  java
  • mysql5.6主从

    1.环境

    操作系统:centos6.5(主服务器IP:192.168.100.170,从服务器IP:192.168.100.171)
    软件版本:mysql5.6.24

    2.开始安装:

      a.主库上设置从库访问的权限

    grant replication slave  on *.* to repl_user@'192.168.100.171' identified by '123456';
    flush privileges;
    可以在从库上用repl_user尝试连接

      b.打开主库的二进制日志,并设置服务标识(server_id)

    vim /etc/my.cnf

    [mysql]

    log-bin = mysql-bin
    binlog_cache_size = 4M
    max_binlog_cache_size = 8M
    max_binlog_size = 512M
    binlog-format = MIXED
    sync-binlog = 1
    server_id = 1
    binlog-ignore-db = mysql
    binlog-ignore-db = information_schema
    binlog-ignore-db = performance_schema
    binlog-ignore-db = test
    auto-increment-increment = 10
    auto-increment-offset = 1

      c.备份主库,和获取同步初态

    FLUSH TABLES WITH READ LOCK;  #锁定数据库
    mysqldump --master-data -root -p py_db > py_db.sql #py_db是我要做主从的库

      获取同步初态:

      主库的备份和同步初态获取完成之后,解锁数据库:

    unlock tables;

      d.从库参数设置,并设置服务标识(server_id)

    vim /etc/my.cnf
    [mysql]
    log-bin = mysql-bin binlog_cache_size = 4M max_binlog_cache_size = 8M max_binlog_size = 512M binlog-format = MIXED sync-binlog = 1 server_id = 2 binlog-ignore-db = mysql binlog-ignore-db = information_schema binlog-ignore-db = performance_schema binlog-ignore-db = test relay_log = mysql-relay-bin log-slave-updates = on

      e.从库导入备份(如果从库没有数据库,需要建立相应的数据库,再进行导入)

    create database py_db default charset utf8;
    mysql -uroot -p py_db < py_db.sql

      如果你刚才导出了多个数据库, 需要把他们都一一上传导入。

      f.开始同步(从库操作)(需要刚才获取的主库初态)。

    mysql> change master to
        -> master_host='192.168.100.170',
        -> master_user='repl_user',
        -> master_password='123456',
        -> master_log_file='mysql-bin.000001',
        -> master_log_pos=120;
    Query OK, 0 rows affected, 2 warnings (0.05 sec)

      g.验证主从状态:

       h.主库试着编辑数据,看看是否从库会同步

     3.常用命令:

    mysql>slave stop;
    mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1        #跳过一个事务
    mysql>slave start
  • 相关阅读:
    微服务架构技术栈选型手册(万字长文)
    Visual Studio 2013 always switches source control plugin to Git and disconnect TFS
    Visual Studio 2013 always switches source control plugin to Git and disconnect TFS
    MFC对话框中使用CHtmlEditCtrl
    ATL开发 ActiveX控件的 inf文件模板
    ActiveX: 如何用.inf和.ocx文件生成cab文件
    Xslt 1.0中使用Array
    如何分隔两个base64字符串?
    An attempt was made to load a program with an incorrect format
    JQuery 公网 CDN
  • 原文地址:https://www.cnblogs.com/vijayfly/p/5227699.html
Copyright © 2011-2022 走看看