做主从复制实验:

第一步:主服务器上操作

1、修改主服务器master:

[root@localhost ~]# vim /etc/my.cnf
server_id = 1  //[必须]服务器唯一ID,默认是1
log-bin=mysql-bin //[必须]启用二进制日志

2、重启主数据库

[root@localhost ~]# systemctl restart mysqld

3、在主服务器上建立帐户并授权slave:

mysql> grant replication slave on *.* to 'zhangsan'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4、登录主服务器的mysql,查询master的状态

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      401 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化

第二步:从服务器操作

1、修改从服务器slave:

[root@localhost ~]# vim /etc/my.cnf
 server_id = 2
log-bin=mysql-bin

2、重启从数据库

[root@localhost ~]# systemctl restart mysqld

3、配置从服务器Slave:

mysql> change master to master_host='192.168.35.131',master_user='zhangsan',master_password='123456', master_log_file='mysql-bin.000001',master_log_pos=401;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4、启动从服务器复制功能并检查从服务器复制功能状态

mysql> start slave;
Query OK, 0 rows affected (0.13 sec)

mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.35.131  //主服务器地址
                  Master_User: zhangsan     //授权帐户名,尽量避免使用root
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 401   //#同步读取二进制日志的位置,大于等于Exec_Master_Log_Pos
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes    //此状态必须YES
            Slave_SQL_Running: Yes    //此状态必须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: 401
              Relay_Log_Space: 460
              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
                  Master_UUID: 31f8646b-484e-11e8-b503-000c298f5b19
             Master_Info_File: /data/mysqldb/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified

注:Slave_IO及Slave_SQL进程必须正常运行,即YES状态,否则都是错误的状态(如:其中一个NO均属错误)。

第三步:检测主从配置

1、在主数据库中创建一个库data,查看从库中是否有

主库中:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> create database data;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| data               |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

2、从库中查看:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| data               |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

能够看到从库中是有data库的,说明主从复制配置完成,但是要注意,从表里不能做更新,删除等操作,只能使用查询,所以要慎重。

总结:完成以上操作过程,主从服务器配置完成。

centos7上mysql5.6版本主从复制的更多相关文章

  1. centos7搭建mysql-5.7.22主从复制

    mysql7.7.22主从复制 本项目是根据真实环境搭建编写出文档,文档中的目录也是根据自己公司环境所创建.公司原来是一台服务器搭建的数据库(5.7.22),由于业务的扩展需要搭建一台从服务器,减轻主 ...

  2. centos7 安装 mysql5.7 版本(全)

    centos 安装 版本说明 :centos7,mysql5.7 ,不是 centos7 可能有些命令不兼容 安装 mysql-server # 下载并安装 mysql yum wget -i -c ...

  3. centos7中安装mysql5.6版本 + 主从复制

    centos安装5.6版本:CentOS7下使用YUM安装MySQL5.6 主从复制:Mysql主从复制与读写分离原理及配置教程 主从复制问题及配置 卸载和安装5.7版本:CentOS 7 安装与卸载 ...

  4. centos7下mysql5.6的主从复制

    一.mysql主从复制介绍 mysql的主从复制并不是数据库磁盘上的文件直接拷贝,而是通过逻辑的binlog日志复制到要同步的服务器本地,然后由本地的线程读取日志里面的sql语句,重新应用到mysql ...

  5. centos7上安装指定版本gitlab

    当我们在做gitlab服务器迁移的时候需要两台服务器中的gitlab相同,如果不同则不让回复git备份.这样我们就要安装指定版本的gitlab. 1. 安装依赖软件 yum -y install po ...

  6. centos7上配置mysql8的主从复制

    注意:1.主库:10.1.131.75,从库:10.1.131.762.server-id必须是纯数字,并且主从两个server-id在局域网内要唯一. [主节点]vi /etc/my.cnf[mys ...

  7. 在 CentOS7 上安装 MySQL5.7

    在 CentOS7 上安装 MySQL5.7 1 通过 SecureCRT 连接到阿里云 CentOS7 服务器: 2 进入到目录 /usr/local/ 中: cd /usr/local/ 3 创建 ...

  8. centos7下安装指定版本mysql5.7.23

    现在mysql版本已经到MySQL 8.0(GA)稳定版本了,所以需求是想简单又快速在centos7下安装指定版本例如MySQL 5.7(GA)版本有下面这种方法 首先需要到mysql官网这里下载对应 ...

  9. 【运维技术】CentOS7上从零开始安装阿里RocketMQ版本:release-4.0.1【亲测哈哈】

    CentOS7上从零开始安装阿里RocketMQ版本:release-4.0.1[亲测哈哈] 安装git # 更新包 $ yum update # 安装git $ yum install git # ...

随机推荐

  1. mybatis 使用merge into

    前一篇博客,oracle的merge into语法 : oracle merge into语法 mybatis 使用merge into,跟一般的update写法相同: <update id=& ...

  2. 2018.12.31 bzoj4001: [TJOI2015]概率论(生成函数)

    传送门 生成函数好题. 题意简述:求nnn个点的树的叶子数期望值. 思路: 考虑fnf_nfn​表示nnn个节点的树的数量. 所以有递推式f0=1,fn=∑i=0n−1fifn−1−i(n>0) ...

  3. s5-1 网络层引言

    网络层要做什么? 源和目的之间的网络有哪些类? 数据报网络  提供无连接的服务 虚电路网络  提供面向连接的服务  网络层的目标:把数据分组一路送到接收机.  网络层利用下层--数据链路层提供的服 ...

  4. JS、JSP、ASP、CGI

      1)JS是在客户端执行的,需要浏览器支持Javascript.JSP是在服务器端执行的,需要服务器上部署支持Servlet的服务器程序.JS代码是能够直接从服务器上download得到,对外是可见 ...

  5. Unicode 字符

    Unicode是计算机可以支持这个星球上多种语言的秘密武器.在Unicode之前,用的都是ASCII. ASCII码非常简单,每个英文都是7位二进制的方式存贮在计算机内,其范围是32~126.当用户在 ...

  6. Html5与Css3知识点拾遗(一)

    1.元素 空元素: 可选的空格空格和斜杠 <img src="x.jpg" width="300" alt="pic" /> & ...

  7. c语言:简单排序:冒泡排序法、选择排序法、插入排序法(待写)

    1.冒泡排序法: 假设有n个数需要按从小到大排序,冒泡排序的原理是,在这一排数字中,将第一个数与第二个数比较大小,如果后面的比前面的小,就将他们交换位置.然后再比较第二个和第三个,再交换,直到第n-1 ...

  8. 关于python logging的 NOTSET 级别

    说重点: NOTSET 意指不设置 所以按照父logger级别来过滤日志 注意 不是最低级别的意思 由于logging中root日志对象的默认级别是WARNING, 所以当你使用logging.get ...

  9. java实现下载excel功能

    1,获取服务器现有excel文件 public List<Object[]> getObject(String filePath){ log.info("**文件路径为:**&q ...

  10. C++ const方法及对象

    一.整体代码 01.cpp #include <iostream> using namespace std; class Test { public: Test(int x) : x_(x ...