log_bin variable must be set to ON.binlog_format variable must be set to ROW.binlog_row_image must be set to FULL.gtid_mode can be set to only ON or OFF. We recommend you set it to ON, because if it is set to OFF, an alarm will be triggered, and if it is set to ON_PERMISSIVE or OFF_PERMISSIVE, an error will be reported.server_id parameter must be set manually and cannot be 0.do_db and ignore_db.log_slave_updates variable must be set to ON.log_bin controls the binlog switch. You need to enable binlog to log all database table structure and data changes. my.cnf configuration file of the source database as follows. As the database needs to be restarted after the log_bin parameter is modified, we recommend you also modify the binlog_format and binlog_row_image parameters based on the verification requirements.my.cnf configuration file is /etc/my.cnf, subject to the actual conditions.log_bin = MYSQL_BINbinlog_format = ROWbinlog_row_image = FULL
[$Mysql_Dir]/bin/mysqladmin -u root -p shutdown[$Mysql_Dir]/bin/safe_mysqld &
[\\$Mysql_Dir] is the installation path of the source database. Replace it with the actual path.show variables like '%log_bin%';
mysql> show variables like '%log_bin%';+------------------+-------+| Variable_name | Value |+------------------+-------+| log_bin | ON |+------------------+-------+| binlog_format | ROW |+------------------+-------+| binlog_row_image | FULL |+------------------+-------+1 row in set (0.00 sec)
binlog_format parameterbinlog_format specifies one of the following three binlog formats:STATEMENT: Each SQL statement that modifies the data will be logged into the binlog of the master. When replicating data, the replica will run the same SQL statements as those in the master. This format can reduce the binlog size. However, the replica may not be able to properly replicate certain functions.ROW: The binlog will log the modifications of each data row, and the replica will modify the same data. This format guarantees the correct source-replica replication, but the binlog size will increase.MIXED: It is a combination of the above two formats. MySQL will automatically select STATEMENT or ROW format to log each executed SQL statement.binlog_format parameter should be set to ROW. If a similar error occurs, fix it as follows:binlog_format.set global binlog_format = ROW;
show variables like '%binlog_format%';
mysql> show variables like '%binlog_format%';+---------------+-------+| Variable_name | Value |+---------------+-------+| binlog_format | ROW |+---------------+-------+1 row in set (0.00 sec)
binlog_row_image parameterbinlog_row_image parameter determines how the binlog logs the pre-image (content before modification) and post-image (content after modification), which directly affects features such as data flashback and source-replica replication.
The binlog_row_image parameter takes effect only if binlog_format is set to ROW. The following describes the effects of specific values:FULL: In ROW format, binlog will log all column data information of the pre-image and post-image.MINIMAL: In ROW format, if a table has no primary key or unique key, the pre-image will log all columns, and the post-image will log the modified columns. If it has a primary key or unique key, both the pre-image and post-image will only log the affected columns.binlog_row_image to FULL to make the source database binlog log the full image. If an error occurs, fix it as follows:binlog_row_image:set global binlog_row_image = FULL;
show variables like '%binlog_row_image%';
mysql> show variables like '%binlog_row_image%';+------------------+-------+| Variable_name | Value |+------------------+-------+| binlog_row_image | FULL |+------------------+-------+1 row in set (0.00 sec)
gtid_mode parametergtid_mode to ON or OFF. We recommend you set it to ON; otherwise, an alarm will be triggered during verification.gtid_mode. When modifying the value, you can only do so in the specified sequence step by step; for example, if you want to change OFF to ON, you should modify the gtid_mode value in the following sequence: OFF > OFF_PERMISSIVE > ON_PERMISSIVE > ON.OFF: All new transactions in the master database and all transactions in the replica database must be anonymous.OFF_PERMISSIVE: All new transactions in the master database must be anonymous. Transactions in the replica database can be anonymous or GTID transactions but cannot be only GTID transactions.ON_PERMISSIVE: All new transactions in the master database must be GTID transactions, and transactions in the replica database can be anonymous or GTID transactions.ON: All new transactions in the master database and all transactions in the replica database must be GTID transactions.gtid_mode = OFF_PERMISSIVE on both the source and replica databases.
On MySQL versions earlier than v5.7.6, you need to modify the parameter in the my.cnf configuration file and restart the database to make the change take effect. On v5.7.6 and later, you can modify the parameter through global naming with no need to restart the database, but you must reset all business connections.set global gtid_mode = OFF_PERMISSIVE;
gtid_mode = ON_PERMISSIVE on both the source and replica databases.set global gtid_mode = ON_PERMISSIVE;
0, the consumption is completed.show variables like '%ONGOING_ANONYMOUS_TRANSACTION_COUNT%';
mysql> show variables like '%ONGOING_ANONYMOUS_TRANSACTION_COUNT%';+-------------------------------------+-------+| Variable_name | Value |+-------------------------------------+-------+| Ongoing_anonymous_transaction_count | 0 |+-------------------------------------+-------+1 row in set (0.00 sec)
gtid_mode = ON on both the source and replica databases.set global gtid_mode = ON;
my.cnf file and restart the database to make the initial values take effect.my.cnf configuration file is /etc/my.cnf, subject to the actual conditions.gtid_mode = onenforce_gtid_consistency = on
server_id parameterserver_id parameter must be set manually and cannot be set to 0. The system default value of this parameter is 1, but the configuration isn't necessarily correct even if the queried parameter value is 1. You still need to manually set it.server_id:set global server_id = 2; // We recommend you set it to an integer above 1. The value here is only an example.
show global variables like '%server_id%';
mysql> show global variables like '%server_id%';+---------------+-------+| Variable_name | Value |+---------------+-------+| server_id | 2 |+---------------+-------+1 row in set (0.00 sec)
do_db and ignore_db settingsdo_db and ignore_db are used to set the filter conditions for binlog.binlog_do_db: Only the specified databases will be logged in the binlog (all databases will be logged by default).binlog_ignore_db: The specified databases will not be logged in the binlog.do_db and ignore_db are set, some cross-database operations will not be logged in the binlog, and source-replica replication will be abnormal; therefore, we recommend you not set them. If a similar error occurs, fix it as follows:my.cnf configuration file in the source database to delete do_db and ignore_db settings.my.cnf configuration file is /etc/my.cnf, subject to the actual conditions.[$Mysql_Dir]/bin/mysqladmin -u root -p shutdown[$Mysql_Dir]/bin/safe_mysqld &
[\\$Mysql_Dir] is the installation path of the source database. Replace it with the actual path.show master status;
mysql> show master status;+---------------+----------+--------------+------------------+-------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+---------------+----------+--------------+------------------+-------------------+| binlog.000011 | 154 | | | |+---------------+----------+--------------+------------------+-------------------+
log_slave_updates parameterlog-bin parameter is enabled in the replica database, data operations directly performed in the replica database can be logged in the binlog, but data replications from the source database to the replica database cannot be logged. Therefore, if the replica database is to be used as the source database of another replica database, the log_slave_updates parameter needs to be enabled. my.cnf configuration file of the source database.my.cnf configuration file is /etc/my.cnf, subject to the actual conditions.log_slave_updates = ON
[$Mysql_Dir]/bin/mysqladmin -u root -p shutdown[$Mysql_Dir]/bin/safe_mysqld &
[\\$Mysql_Dir] is the installation path of the source database. Replace it with the actual path.show variables like '%log_slave_updates%';
mysql> show variables like '%log_slave_updates%';+-------------------+-------+| Variable_name | Value |+-------------------+-------+| log_slave_updates | ON |+-------------------+-------+1 row in set (0.00 sec)
Feedback