zoukankan      html  css  js  c++  java
  • mysql 配置主从

    1、选择2个ip,1个为主,1个为从:
    例:
    主:192.168.12.76 从:192.168.12.77
    2、在192.168.12.76的my.cnf 配置master,添加如下:(红色为添加的内容)
    #vi my.cnf
    [mysqld]
    basedir=/export/servers/mysql
    datadir=/export/servers/mysql/data
    log-error=/export/servers/mysql/mysql_error.log
    pid-file=/export/servers/mysql/mysql.pid
    user=mysql
    tmpdir=/tmp
    log-bin=master-bin
    log-bin-index=master-bin.index
    server-id=1


    在192.168.12.77的my.cnf 配置slave,添加如下:(红色为添加内容)
    #vi my.cnf
    [mysqld]
    basedir=/export/servers/mysql
    datadir=/export/servers/mysql/data
    log-error=/export/servers/mysql/mysql_error.log
    pid-file=/export/servers/mysql/mysql.pid
    user=mysql
    tmpdir=/tmp
    server-id=2
    relay-log-index=slave-relay-bin.index
    relay-log=slave-relay-bin
    3、重启两台服务器的mysql:
    #./mysql restart

    4、在主服务器上建立账户并授权slave:
    mysql>use mysql;
    mysql> create user master;

    mysql>grant replication slave on *.* to master identified by '123456'; (GRANT REPLICATION SLAVE ON *.* to 'master'@'%' identified by 'q123456';)
    5、查询master状态:
    show master status;
    +------------------+----------+--------------+------------------+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000004 | 308 | | |
    +------------------+----------+--------------+------------------+
    6、配置从服务器slave:
    mysql>use mysql;
    mysql> change master to master_host='192.168.12.76',master_port=3306,master_user='master',master_password='123456',master_log_file='mysql-bin.000004',master_log_pos=308;
    mysql>flush privileges;
    mysql>show slave statusG
    mysql>slave start;
    Slave_IO_Running: Yes //此状态必须YES
    Slave_SQL_Running: Yes //此状态必须YES
    Read_Master_Log_Pos: 600 //#同步读取二进制日志的位置,大于等于>=Exec_Master_Log_Pos
    7、在主库上创建一个数据库,在从库查看是否存在,存在为ok。

  • 相关阅读:
    【HAOI2014】贴海报
    【HAOI2016】食物链
    【NOI2003】银河英雄传
    【HAOI2013】花卉节
    【BZOJ1702】[usaco2007margold]队列平衡
    【网络流24】餐巾
    洛谷 [P1265] 公路修建
    全排列与 康托展开
    洛谷 [P1403] 约数研究
    高精度模板
  • 原文地址:https://www.cnblogs.com/hankyoon/p/5169575.html
Copyright © 2011-2022 走看看