美文网首页
主从不同步(Slave_IO_Running: Connecti

主从不同步(Slave_IO_Running: Connecti

作者: 老柿子 | 来源:发表于2020-06-02 19:00 被阅读0次

    主从不同步(Slave_IO_Running: Connecting)

    在从库上面查看:

    mysql> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Connecting to master
                 Slave_IO_Running: Connecting
                Slave_SQL_Running: Yes
    

    查看从库状态:

    show slave status\G;

    记得关注这么几个字段

    mysql> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Connecting to master
                      Master_Host: 127.0.0.1
                      Master_User: slave
                      Master_Port: 3307
                    Connect_Retry: 60
                   // 下面这个表示从库中读取到的主库的文件
                  Master_Log_File: mysql-bin.000001
                // 下面这个表示从库中读取到的主库文件中的位置
              Read_Master_Log_Pos: 858
                  // 下面这个表示从库中SQL线程执行的文件
                   Relay_Log_File: shizi-2-relay-bin.000001
                    Relay_Log_Pos: 4
            Relay_Master_Log_File: mysql-bin.000001
                 Slave_IO_Running: Connecting
                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
            // 下面这个表示从库中SQL线程执行的文件的位置
              Exec_Master_Log_Pos: 858
                  
    

    然后查看下主库中的binary log文件

    查看主库

    show binary logs;

    mysql> show binary logs;
    +------------------+-----------+-----------+
    | Log_name         | File_size | Encrypted |
    +------------------+-----------+-----------+
    | mysql-bin.000001 |     27893 | No        |
    | mysql-bin.000002 |      2297 | No        |
    | mysql-bin.000003 |     37078 | No        |
    +------------------+-----------+-----------+
    3 rows in set (0.00 sec)
    

    查看当前状态

    show master status;

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

    可以看到是从库的IO线程没有将数据给同步过来,只同步了主库的 0001文件中的靠前的位置。我们看下从库的日志

    查看从库日志

    show variables like 'log_error';

    mysql> show variables like 'log_error';
    +---------------+-----------------------------------------------------+
    | Variable_name | Value                                               |
    +---------------+-----------------------------------------------------+
    | log_error     | /Users/zhouzhenyong/mysql-cluster/slave1/mysqld.log |
    +---------------+-----------------------------------------------------+
    1 row in set (0.00 sec)
    

    看到这里有大量的这个错误

    Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection. Error_code: MY-002061
    

    原因是mysql8的密码方式采用的跟之前的不同,需要这么来使用就可以了在从库进行授权位置的时候添加参数:get_master_public_key=1,就可以了
    鉴于我们的从库已经有一段没有同步了,那么从那个没有同步的位置开始(即主库的858位置)

    进入从库:

    // 停止
    stop slave;
    // 重新授权

    change master to master_host='127.0.0.1',master_port=3307,master_user='slave',master_password='slave1234',master_log_file='mysql-bin.000001',master_log_pos=858,get_master_public_key=1;
    // 启动从库
    start slave;
    // 查看状态
    show status slave;

    mysql> show slave status\G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 127.0.0.1
                      Master_User: slave
                      Master_Port: 3307
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000003
              Read_Master_Log_Pos: 37078
                   Relay_Log_File: shizi-2-relay-bin.000004
                    Relay_Log_Pos: 37293
            Relay_Master_Log_File: mysql-bin.000003
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
    

    参考:

    http://blog.itpub.net/30393770/viewspace-2660966/

    相关文章

      网友评论

          本文标题:主从不同步(Slave_IO_Running: Connecti

          本文链接:https://www.haomeiwen.com/subject/jpjpzhtx.html