mysql5.6-"5.7

Source: Internet
Author: User


This experiment will use MySQL 5.6.x as a multi-"master".

0 test Environment:
OS: CentOS 6.5
master_1: 192.168.1.185 (MySQL 5.6.30)
master_2: 192.168.1.186 (MySQL 5.6.30)
slave: 192.168.1.1.187 (MySQL 5.7.15)

0 Configuration:
Master_1 Related configurations:

    1. [Mysqld]
    2. server_id = 185
    3. Log-bin = master_1
    4. Log-bin-index = Master_1.index


Master_2 Related configurations:

    1. [Mysqld]
    2. server_id = 186
    3. Log-bin = master_2
    4. Log-bin-index = Master_2.index

Slave related configurations:

    1. [Mysqld]
    2. server_id = 187
    3. Relay-log = Slave
    4. Relay-log-index = Slave.index
    5. # slave in a multi-source replication structure, the official requirements for Master-info and relay-log-info repositories must be table.
    6. # If it is file, it will fail when multiple master is added: Er_slave_new_channel_wrong_repository.
    7. Master-info-repository = TABLE
    8. Relay-log-info-repository = TABLE

0 Create a replication user on master_1 & master_2:

    1. GRANT REPLICATION SLAVE On * * to [e-mail protected] ' 192.168.1.187 ' identified by ' repl ';
    2. FLUSH privileges;

0 Test Data Preparation:
master_1 test Data:

    1. Master_1> FLUSH LOGS;
    2. Query OK, 0 rows Affected (0.00 sec)
    3. master_1> SHOW BINARY LOGS; --Remember the name and position of the current Binlog
    4. +-----------------+-----------+
    5. | Log_name | File_size |
    6. +-----------------+-----------+
    7. | master_1.000001 | 166 |
    8. | master_1.000002 | 455 |
    9. | master_1.000003 | 120 |
    10. +-----------------+-----------+
    11. 3 Rows in Set (0.00 sec)
    12. master_1> CREATE DATABASE master_1;
    13. Query OK, 1 row affected (0.03 sec)

Master_2 test Data:

    1. Master_2> FLUSH LOGS;
    2. Query OK, 0 rows Affected (0.00 sec)
    3. master_2> SHOW BINARY LOGS; --Remember the name and position of the current Binlog
    4. +-----------------+-----------+
    5. | Log_name | File_size |
    6. +-----------------+-----------+
    7. | master_2.000001 | 166 |
    8. | master_2.000002 | 455 |
    9. | master_2.000003 | 120 |
    10. +-----------------+-----------+
    11. 3 Rows in Set (0.00 sec)
    12. master_2> CREATE DATABASE master_2;
    13. Query OK, 1 row affected (0.02 sec)

0 performed on Slave:

  1. Salve> Change MASTER to
  2. Master_host= ' 192.168.1.185 ',
  3. Master_user= ' Repl ',
  4. master_port=3306,
  5. Master_password= ' Repl ',
  6. Master_log_file= ' master_1.000003 ',
  7. master_log_pos=120
  8. For CHANNEL ' master_1 ';
  9. Query OK, 0 rows affected, 2 warnings (0.02 sec)-The warnings generated here are some security recommendations and warnings that this experiment ignores.
  10. Salve> Change MASTER to
  11. Master_host= ' 192.168.1.186 ',
  12. Master_user= ' Repl ',
  13. master_port=3306,
  14. Master_password= ' Repl ',
  15. Master_log_file= ' master_2.000003 ',
  16. master_log_pos=120
  17. For CHANNEL ' master_2 ';
  18. Query OK, 0 rows affected, 2 warnings (0.02 sec)
  19. slave> START Slave;
  20. Query OK, 0 rows affected (0.01 sec)
  21. Salve> SHOW DATABASES; -The Binlog events on master_1 and master_2 have been properly apply.
  22. +--------------------+
  23. | Database |
  24. +--------------------+
  25. | Information_schema |
  26. | master_1 |
  27. | master_2 |
  28. | MySQL |
  29. | Performance_schema |
  30. | SYS |
  31. +--------------------+
  32. 6 rows in Set (0.00 sec)

Finally, the replication status can be found through the start slave status

  1. slave> SHOW Slave Status\g
  2. 1. Row ***************************
  3. Slave_io_state:waiting for Master to send event
  4. master_host:192.168.1.185
  5. Master_user:repl
  6. master_port:3306
  7. ............................................................
  8. Slave_io_running:yes
  9. Slave_sql_running:yes
  10. ............................................................
  11. master_server_id:185
  12. Master_uuid:ee1f8704-58c4-11e6-95b5-000c297f23b7
  13. Master_Info_File:mysql.slave_master_info
  14. sql_delay:0
  15. Sql_remaining_delay:null
  16. Slave_sql_running_state:slave have read all relay log; Waiting for more updates
  17. ............................................................
  18. Channel_name:master_1
  19. Master_tls_version:
  20. 2. Row ***************************
  21. Slave_io_state:waiting for Master to send event
  22. master_host:192.168.1.186
  23. Master_user:repl
  24. master_port:3306
  25. Connect_retry:60
  26. ............................................................
  27. Slave_io_running:yes
  28. Slave_sql_running:yes
  29. ............................................................
  30. master_server_id:186
  31. master_uuid:53774f2d-7e14-11e6-8900-000c298e914c
  32. Master_Info_File:mysql.slave_master_info
  33. sql_delay:0
  34. Sql_remaining_delay:null
  35. Slave_sql_running_state:slave have read all relay log; Waiting for more updates
  36. ............................................................
  37. Channel_name:master_2
  38. Master_tls_version:
  39. 2 rows in Set (0.00 sec)

0 Test:
Operation on master_1:

    1. Master_1> CREATE TABLE master_1.test_table (id int);
    2. Query OK, 0 rows affected (0.05 sec)
    3. Master_1> INSERT into master_1.test_table SELECT 666666;
    4. Query OK, 1 row affected (0.01 sec)
    5. Records:1 duplicates:0 warnings:0

Operation on master_2:

    1. Master_2> CREATE TABLE master_2.test_table (massage varchar (16));
    2. Query OK, 0 rows affected (0.02 sec)
    3. Master_2> INSERT into master_2.test_table SELECT ' hehe hey ';
    4. Query OK, 1 row Affected (0.00 sec)
    5. Records:1 duplicates:0 warnings:0
    6. Master_2> INSERT into master_2.test_table SELECT ' samyang inflammation ';
    7. Query OK, 1 row Affected (0.00 sec)
    8. Records:1 duplicates:0 warnings:0

Operation on Slave:

    1. salve> SELECT ID from master_1.test_table;
    2. +--------+
    3. | ID |
    4. +--------+
    5. | 666666 |
    6. +--------+
    7. 1 row in Set (0.00 sec)
    8. salve> SELECT massage from master_2.test_table;
    9. +--------------+
    10. | Massage |
    11. +--------------+
    12. | Hey heh |
    13. | Samyang of the disease |
    14. +--------------+
    15. 2 rows in Set (0.00 sec)

0 Other related syntax:

    1. Start/stop/reset all/reset SLAVE for CHANNEL ' XXX ';
    2. SHOW SLAVE STATUS for CHANNEL ' XXX ';

Ps.
Similar to the traditional position method described above, the Gtid mode is similarly configured, after opening the Gtid, you need to pay attention to using the for CHANNEL ' xxx ' keyword, such as:

    1. Change MASTER to
    2. Master_host= ',
    3. Master_user= ' Repl ',
    4. master_port=3306,
    5. Master_password= ' Repl ',
    6. Master_auto_position = 1
    7. For CHANNEL ' master_1 ';


Multiple hosts of the schema name can not be the same, (for example, master_1 for db_00 ... db_09 total 10 libraries, master_2 for db_10 ... db_19,master_3 ... db_20 ... )

mysql5.6-"5.7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.