Alice52 / project

This repository is muti language and tech integration project.
MIT License
0 stars 0 forks source link

[ec] config mysql master slave #106

Closed Alice52 closed 3 years ago

Alice52 commented 3 years ago

config mysql master-slave by docker

Alice52 commented 3 years ago
  1. login master and grant

    flush logs;
    grant replication slave on *.* to 'backup'@'%' identified by '123456';
    FLUSH PRIVILEGES;
  2. handle legacy data and start slave sync

    -- master
    -- 1. frozen master data
    mysql> flush tables with read lock;
    -- 2. new terminal and backup data
    mysqldump -h 127.0.0.1 -uroot -proot --skip-comments --databases --compact -C -q -f db1 db2  db3 >> back.sql
    -- 3. obtain master bin-log postion
    mysql> show master status;
    -- 4. unfrozen master data
    mysql> unlock tables;
    
    -- slave
    -- 1. import data from backup
    $ mysql -uroot -proot <back.sql
    -- 2. set connection to master with bin-log position
    CHANGE MASTER TO MASTER_HOST='172.18.135.185',MASTER_PORT=3306,MASTER_USER='repl',
    MASTER_PASSWORD='repl',MASTER_LOG_FILE='mysql-bin.000028',MASTER_LOG_POS=4032;
    -- 3. enable slave
    mysql> start slave;
  3. set slave read only

    -- set read only
    SET GLOBAL READ_ONLY=1;
    set global super_read_only=ON;