1. Realistic Background There are 4 hosts, all of which can automatically collect data and store it in their MySQL database, and there is another high-configuration main server dedicated to processing data. These five machines are often not in the same network segment, but it is hoped that once they are in the same network segment, the four hosts used to collect data can automatically collect data from the main server, and the environment is configured for this purpose. 2. Agreement
3. Configure the master 3.1. Configuring startup parameters For multiple masters, you only need to ensure that the server-id is inconsistent, and configure the rest according to your own needs. [mysqld] # Server identifier, make sure each server identifier is different server-id = 1000 # The master machine must have log_bin enabled # mysql-bin is a custom name, and files such as mysql-bin.index, mysql-bin.000001, etc. will be generated log_bin=mysql-bin # Binary log expiration time (unit: day), the default value is 0, that is, it does not expire expire_logs_days = 0 # Error log log-error=/var/lib/mysql/mysql-error.log # The maximum value of a single log_bin file. When the maximum value is reached, the suffix of the newly created file will be automatically increased, such as mysql-bin.000002 max_binlog_size = 100M #mysql installation path basedir=/var/lib/mysql #mysql data path datadir=/var/lib/mysql # The database where the master records the operation is binlog_do_db=replication # Database ignored by master binlog_ignore_db=information_schema binlog_ignore_db=performance_schema binlog_ignore_db=sys binlog_ignore_db=mysql # Binary log storage mode binlog_format=MIXED # Maximum storage value of blob type (unit: bytes, B) # 1048576 B = 1MB max_allowed_packet=1048576 # Password complexity configuration, requires plugin # Password length must be at least 0 # validate_password_length=8 # Minimum number of uppercase and lowercase characters # validate_password_mixed_case_count=1 # The minimum number of numbers in the password# validate_password_number_count=1 # The minimum number of special characters in the password # validate_password_special_char_count=1 innodb_flush_log_at_trx_commit=0 [mysql] default-character-set=utf8mb4 [client] default-character-set=utf8mb4 3.2. Restart the service to make the parameters take effect 3.3. Log in as root, create a user, assign a password, authorize, and refresh permissions Create user replication and assign a password: create user 'replication'@'%' identified with mysql_native_password by 'JINGhuaSHUIyue123,.'; If the user creation fails, the user may already exist. If it is not important, you can delete the user: drop user 'replication'@'%'; If you do not want to delete and rebuild the user, but only want to change the password: alter user 'replication'@'%' identified with mysql_native_password by 'JINGhuaSHUIyue123,.'; Grant the user replication slave permissions: grant replication slave on *.* to 'replication'@'%'; Ensure that the replication slave permissions take effect immediately and refresh the permissions: flush privileges; 4. Configure the slave server 4.1. Configuring startup parameters[mysqld] # Server identifier, make sure each server identifier is different server-id = 2000 #mysql installation path basedir=D:\mysql #mysql data path datadir=D:\mysql\data # slave replicated database replicate_do_db=test # The database ignored by the slave replicate_ignore_db=information_schema replicate_ignore_db=performance_schema replicate_ignore_db=mysql replicate_ignore_db=sys # Slave network timeout reconnection interval (unit: seconds) slave_net_timeout=60 [mysql] default-character-set=utf8 [client] default-character-set=utf8 4.2. Restart the service to make the parameters take effect 5. Configure multiple masters and one slave 5.1. Check the master status Log in to master1 as root and pay attention to the file and position: show master status; +------------------+----------+--------------+-------------------------------------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+-------------------------------------------------+-------------------+ | mysql-bin.000006 | 155 | test | information_schema,performance_schema,sys,mysql | | +------------------+----------+--------------+-------------------------------------------------+-------------------+ Log in to master1 as root and pay attention to the file and position: show master status; +------------------+----------+--------------+-------------------------------------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+-------------------------------------------------+-------------------+ | mysql-bin.000005 | 155 | test | information_schema,performance_schema,sys,mysql | | +------------------+----------+--------------+-------------------------------------------------+-------------------+ Note: Starting MySQL will force the generation of a new log-bin, so the location is 155. 5.2. Configuring the slave-master relationship Check if there are any other residual configurations: show slave status\G; Stop the slave and clear the remaining configuration: stop slave; reset slave all; Configure the replication channel "master1" according to the file and position of master1 change master to master_host = '112.124.1.100', master_user = 'replication', master_port = 3306, master_password = 'replication', master_log_file = 'mysql-bin.000006', master_log_pos = 155, master_connect_retry = 15, master_retry_count = 0 for channel 'master1'; Configure the replication channel "master2" according to the file and position of master2 change master to master_host = '192.168.1.139', master_user = 'replication', master_port = 3306, master_password = 'JINGhuaSHUIyue123,.', master_log_file = 'mysql-bin.000005', master_log_pos = 155, master_connect_retry = 15, master_retry_count = 0 for channel 'master2';
5.3. Prepare the table Before starting, use DDL statements in the databases of the three machines to define the table structure, and keep the table structure consistent to ensure consistency before master-slave replication, otherwise an error will occur! 5.4. Start slave and check slave statusstart slave for channel 'master1'; start slave for channel 'master2'; show slave status\G; Note that both Slave_IO_Running and Slave_Slave_Running need to display Yes to indicate success, otherwise pay attention to the error prompt. This is the end of this article about configuring multiple masters and one slave in MySQL 8.0.18. For more information about MySQL multiple masters and one slave, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: The basic use of html includes links, style sheets, span and div, etc.
>>: CSS overflow-wrap new property value anywhere usage
Table of contents 1. Implementation process of qu...
Gtid + Mha + Binlog server configuration: 1: Test...
--1. Create a new group and user for mysql # user...
Problem Description Recently, there was a MySQL5....
Preface This article contains 1. Several major co...
1. Install basic components First, execute the yu...
Table of contents 1. Add monitoring Linux host 2....
Table of contents 1. props/$emit Introduction Cod...
The creation of the simplest hello world output i...
1. Create a test table CREATE TABLE `testsign` ( ...
Links to the current page. ------------------- Com...
1. Command Introduction The seq (Sequence) comman...
At present, most people who use Linux either use ...
MySQL is a free relational database with a huge u...
Start the mysql container in docekr Use command: ...