• 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。

  • 相关阅读:
    0929作业
    0909上机作业
    熟悉的LINUX操作
    博客搭建成功啦!
    感谢管理员,通过了我的博客邀请。哈哈
    Asp.net常用的51个代码(非常实用)
    CSS命名规范:
    常用的JavaScript验证正则表达式
    Linq to sql 查询句法
    Web.config配置文件详解
  • 原文地址:https://www.cnblogs.com/hankyoon/p/5169575.html
Copyright © 2020-2023  润新知