zoukankan      html  css  js  c++  java
  • Mysql主从复制

    Mysql主从复制也叫作Replication

    1 他的原理

       http://www.cnblogs.com/crazylqy/p/4065374.html

       

    2 他的实现

    这里有一个专题专门对mysql从历史到发展到架构,到mysql集群都有比较详细的介绍:http://www.cnblogs.com/crazylqy/category/625963.html

    3 具体实现步骤

    http://www.cnblogs.com/alvin_xp/p/4162249.html

    4 遇到的问题

      1)MySQL error code 1872 (ER_SLAVE_RLI_INIT_REPOSITORY): Slave failed to initialize relay log info structure from the repository

       解决办法:重置从数据库连接,http://www.cnblogs.com/Bccd/p/5856716.html

    5 详细的主数据库配置参考

      

    [client]

    port=5869

    [mysql]

    default-character-set=utf8


    [mysqld]

    port=5869
    #basedir=D:/mysql-5.6.21-winx64
    #datadir=D:/mysql-5.6.21-winx64/data
    character-set-server=utf8
    default-storage-engine = MYISAM
    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

    log-bin=mysql-bin #slave会基于此log-bin来做replication
    log-bin-index=mysql-bin.index
    server-id=11 #master的标示
    read-only=0
    binlog-do-db=xsmart_mssp_basedatacenter #同步数据库,可以复制写多个
    binlog-ignore-db=mysql #忽略需要同步的数据库,可以复制写多个
    log-slave-updates=1 #这个参数一定要加上,否则不会给更新的记录写入到二进制文件中
    innodb_flush_log_at_trx_commit=1
    sync_binlog=1
    skip-external-locking #加上可以避免因资源锁引起MySQL服务停止
    skip-name-resolve #加上可以避免因资源锁引起MySQL服务停止

    max_connections=300
    query_cache_size=186M
    table_open_cache=1520
    tmp_table_size=67M
    thread_cache_size=38
    myisam_max_sort_file_size=100G
    myisam_sort_buffer_size=67M
    key_buffer_size=290M
    read_buffer_size = 1M
    read_rnd_buffer_size = 8M
    sort_buffer_size = 1M
    #innodb_additional_mem_pool_size=80M
    #innodb_flush_log_at_trx_commit=0
    #innodb_log_buffer_size=8M
    #innodb_buffer_pool_size=2G
    #innodb_log_file_size=1024M
    #innodb_thread_concurrency=18
    #innodb_support_xa = 1
    #innodb_file_per_table = 1
    #innodb_file_format = Barracuda

    #interactive_timeout = 2147482
    #wait_timeout = 2147482
    interactive_timeout = 86400
    wait_timeout = 86400
    max_allowed_packet = 1G

    # binlog
    #log_bin = D:/mysql-5.6.21-winx64/log/binlog/mysql-bin.log
    #log_bin_index = D:/mysql-5.6.21-winx64/log/binlog/mysql-bin.index
    #log_error = D:/mysql-5.6.21-winx64/log/mysql-error.log
    sync_binlog = 1
    expire_logs_days = 7
    binlog_format = MIXED

    [mysqldump]
    max_allowed_packet = 1G

    6 主数据库执行的语句参考

    CREATE USER repl; `创建一个主从复制的数据库用户,rel
    GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.50.%' IDENTIFIED BY 'mysql';'为这个用户赋权限,且他的密码为mysql

    SHOW MASTER STATUS;'显示主数据库主从复制运行状态

    7 从数据库执行语句参考

    STOP SLAVE;‘停止与主数据库连接
    RESET SLAVE ALL;'重置与主数据库连接
    CHANGE MASTER TO MASTER_HOST='192.168.50.192',
    MASTER_PORT=5869,
    MASTER_USER='repl',
    MASTER_PASSWORD='mysql',
    MASTER_LOG_FILE='mysql-bin.000006',
    MASTER_LOG_POS=5750;


    START SLAVE;'启动与主数据库连接并开始主从复制

    SHOW SLAVE STATUS;’查看主从复制运行状态,当看到Slave_IO_Running和Slave_SQL_Running都为Yes的时候,证明同步成功,否则就看sql执行错误日志

  • 相关阅读:
    论分治与归并思想
    关于缩短cin时间的方法
    【lower_bound、upperbound讲解、二分查找、最长上升子序列(LIS)模版】
    getDomain(url)-我的JavaScript函数库-mazey.js
    jQuery-PHP跨域请求数据
    ASP-Server.Transfer-Response.Redirect
    jQuery获取相邻标签的值
    分界线<hr/>
    jQuery获取input复选框的值
    Bootstrap支持的JavaScript插件
  • 原文地址:https://www.cnblogs.com/rjjs/p/7452766.html
Copyright © 2011-2022 走看看