zoukankan      html  css  js  c++  java
  • canal mysql slave

    [mysqld]
    log-bin=mysql-bin #添加这一行就ok
    binlog-format=ROW #选择row模式
    server_id=1 #配置mysql replaction需要定义,不能和canal的slaveId重复

    b. canal的原理是模拟自己为mysql slave,所以这里一定需要做为mysql slave的相关权限.

    CREATE USER canal IDENTIFIED BY 'canal';  
    GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
    -- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
    FLUSH PRIVILEGES;
    1. Download and add the repository, then update.

       
      wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
      sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
      yum update
      
    2. Install MySQL as usual and start the service. During installation, you will be asked if you want to accept the results from the .rpm file’s GPG verification. If no error or mismatch occurs, enter y.

       
      sudo yum install mysql-server
      sudo systemctl start mysqld
    sudo nano /etc/mysql/my.cnf

    We have to make sure that we have a few things set up in this configuration. The first is the server-id. This number, as mentioned before needs to be unique. Since it is set on the default (still 1), be sure to change it’s something different.

    server-id               = 2

    Following that, make sure that your have the following three criteria appropriately filled out:

    relay-log               = /var/log/mysql/mysql-relay-bin.log
    log_bin                 = /var/log/mysql/mysql-bin.log
    binlog_do_db            = newdatabase

    You will need to add in the relay-log line: it is not there by default. Once you have made all of the necessary changes, save and exit out of the slave configuration file.

    Restart MySQL once again:

    sudo service mysql restart

    The next step is to enable the replication from within the MySQL shell.

    Open up the the MySQL shell once again and type in the following details, replacing the values to match your information:

    CHANGE MASTER TO MASTER_HOST='12.34.56.789',MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=  107;

    This command accomplishes several things at the same time:

    1. It designates the current server as the slave of our master server.
    2. It provides the server the correct login credentials
    3. Last of all, it lets the slave server know where to start replicating from; the master log file and log position come from the numbers we wrote down previously.

    With that—you have configured a master and slave server.

    Activate the slave server:

    START SLAVE;

    You be able to see the details of the slave replication by typing in this command. The G rearranges the text to make it more readable.

    SHOW SLAVE STATUSG

    If there is an issue in connecting, you can try starting slave with a command to skip over it:

    SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; SLAVE START; 




    MySQL 错误处理 Got fatal error 1236 from master when reading data from binary log

    在master那边,执行:

    flush logs;
    show master status;

    记下File, Position。

    在slave端,执行:

    CHANGE MASTER TO MASTER_LOG_FILE='testdbbinlog.000xxxx',MASTER_LOG_POS=xxxxx;
    slave start;
    show slave status G

  • 相关阅读:
    Android Studio开发JNIproject
    POJ 3006 Dirichlet's Theorem on Arithmetic Progressions 快筛质数
    ZooKeeper是什么?
    android学习记录(十三)Task 和 Activity 回退栈操作。
    Java程序员的日常—— IOUtils总结
    sql基础知识:分页+排序
    Elasticsearch推荐插件篇(head,sense,marvel)
    sql基础知识:日期的常用用法
    [大数据之Spark]——Actions算子操作入门实例
    [大数据之Spark]——Transformations转换入门经典实例
  • 原文地址:https://www.cnblogs.com/studyNT/p/10403560.html
Copyright © 2011-2022 走看看