zoukankan      html  css  js  c++  java
  • mariadb master and salve configure

    mariadb master and salve configure
    
    主从复制配置:
    
    master:192。168.8.200
    salve:192.168.8.201
    
    主服务器配置:
    
    主服务器需要启动二进制日志,主服务器每次数据的改变,都会记录到二进制日志;
    配置主服务my.cnf文件;
    [root@localhost data]# egrep -v "^$|^#" /etc/my.cnf
    datadir = /mydata/data
    skip_name_resolve = ON     //跳过域名解析
    innodb_file_per_table = ON   //innodb使用独立表空间;
    log-bin=mysql-bin			//启动二进制日志
    binlog_format=mixed			//日志滚动方式;
    server-id	= 1             //唯一id
    创建可复制权限账号:
    MariaDB [(none)]> grant replication slave,replication client on *.* to 'glq'@'192.168.%.%' identified by '123123';
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> show master status;     //查看二进制日志文件file和postion,需要在slave制定复制日志信息;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000005 |      245 |              |                  |
    +------------------+----------+--------------+------------------+
    1 row in set (0.01 sec)
    
    从服务器配置:
    [root@localhost ~]# egrep -v "^$|^#" /etc/my.cnf
    skip_name_resolve = ON
    innodb_file_per_table = ON
    datadir =  /mydata/data
    relay-log = relay-log		//开启中继日志;
    relay-log = relay-log.index
    log-bin=mysql-bin
    binlog_format=mixed
    server-id	= 2
    [root@localhost ~]# service mysqld restart
    MariaDB [(none)]> change master to master_host='192.168.8.200',master_user='glq',master_password='123123',master_log_file='mysql-bin.000005',master_log_pos='245';    //设置复制线程,指定master password,user,二进制日志信息;
    
    MariaDB [(none)]> start slave;     启动从server
    MariaDB [(none)]> show slave statusG
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 192.168.8.200
                      Master_User: glq
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000005
              Read_Master_Log_Pos: 765
                   Relay_Log_File: relay-log.000002
                    Relay_Log_Pos: 1049
            Relay_Master_Log_File: mysql-bin.000005
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
                  Replicate_Do_DB: 
              Replicate_Ignore_DB: 
               Replicate_Do_Table: 
           Replicate_Ignore_Table: 
          Replicate_Wild_Do_Table: 
      Replicate_Wild_Ignore_Table: 
                       Last_Errno: 0
                       Last_Error: 
                     Skip_Counter: 0
              Exec_Master_Log_Pos: 765
                  Relay_Log_Space: 1337
                  Until_Condition: None
                   Until_Log_File: 
                    Until_Log_Pos: 0
               Master_SSL_Allowed: No
               Master_SSL_CA_File: 
               Master_SSL_CA_Path: 
                  Master_SSL_Cert: 
                Master_SSL_Cipher: 
                   Master_SSL_Key: 
            Seconds_Behind_Master: 0
    Master_SSL_Verify_Server_Cert: No
                    Last_IO_Errno: 0
                    Last_IO_Error: 
                   Last_SQL_Errno: 0
                   Last_SQL_Error: 
      Replicate_Ignore_Server_Ids: 
                 Master_Server_Id: 1
    1 row in set (0.00 sec)
    至此从服务器配置完成。
    
    在主服务器创建数据库,插入数据
    MariaDB [(none)]> create database testdb;
    Query OK, 1 row affected (0.00 sec)
    
    MariaDB [(none)]> use testdb;
    Database changed
    MariaDB [testdb]> create table GEELY(id int unsigned not null auto_increment primary key,name char(20) not null,cardID varchar(10));
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [testdb]> desc GEELY
        -> ;
    +--------+------------------+------+-----+---------+----------------+
    | Field  | Type             | Null | Key | Default | Extra          |
    +--------+------------------+------+-----+---------+----------------+
    | id     | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | name   | char(20)         | NO   |     | NULL    |                |
    | cardID | varchar(10)      | YES  |     | NULL    |                |
    +--------+------------------+------+-----+---------+----------------+
    3 rows in set (0.00 sec)
    
    MariaDB [testdb]> insert into GEELY(name,cardID)values('glq',123123),('zyn',123321);
    Query OK, 2 rows affected (0.01 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    MariaDB [testdb]> select * from GEELY;
    +----+------+--------+
    | id | name | cardID |
    +----+------+--------+
    |  1 | glq  | 123123 |
    |  2 | zyn  | 123321 |
    +----+------+--------+
    2 rows in set (0.00 sec)
    
    在从服务器查看是否同步
    MariaDB [(none)]> use testdb;
    Database changed
    MariaDB [testdb]> select * from GEELY;
    +----+------+--------+
    | id | name | cardID |
    +----+------+--------+
    |  1 | glq  | 123123 |
    |  2 | zyn  | 123321 |
    +----+------+--------+
    2 rows in set (0.00 sec)
    至此主从服务配置完成;
  • 相关阅读:
    jsp mysql 配置线程池
    服务端 模拟 检测 攻击。。乱写
    硕思闪客精灵 7.2 破解版
    unity UnityAwe 插件
    smartfoxserver 2x 解决 Math NAN
    unity 断点下载
    java 监听文件目录修改
    wind7 64 setup appjs
    sfs2x 修改jvm 内存
    unity ngui 解决图层问题
  • 原文地址:https://www.cnblogs.com/ligao/p/6386743.html
Copyright © 2011-2022 走看看