Setting up semi-synchronous replication in MySQL
The steps for setting up MySQL semi-synchronous replication are as follows: 1. Confirm the version supports and load the plug-in; 2. Turn on and enable semi-synchronous mode; 3. Check the status and operation status; 4. Pay attention to timeout settings, multi-slave library configuration and master-slave switching processing. It is necessary to ensure that MySQL version 5.5 and above, install the rpl_semi_sync_master and rpl_semi_sync_slave plugins, enable the corresponding parameters in the master and slave library, and configure automatic loading in my.cnf, restart the service after the settings are completed, check the status through SHOW STATUS, reasonably adjust the timeout time and monitor the plug-in operation.
Semi-Synchronous Replication of MySQL is a compromise replication method. The master library waits for at least one slave library to confirm that the log is received before continuing to execute when submitting a transaction. Compared with asynchronous replication, it is safer and better than full synchronization in performance. It is suitable for scenarios where data consistency requirements are high but cannot accept full synchronization performance losses.

Next, let’s talk about how to set up MySQL semi-synchronous replication, including basic premises, configuration steps and some points that need to be paid attention to.

Confirm MySQL version and plug-in support
To use semi-synchronous replication, first make sure your version of MySQL supports it. Generally speaking:
- MySQL 5.5 and above starts to support
- 5.7 or 8.0 is recommended because the functions are more complete
- Need to load
semisync_master
andsemisync_slave
plugins
You can check whether these plugins have been loaded by:

SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE '%semisync%';
If not loaded, you can execute it on the master and slave libraries separately:
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
Note: The .so
files may be called slightly differently in different systems. For example, some are libsemisync_master.so
, which are adjusted according to the actual path.
Turn on and enable semi-synchronous copy mode
After installing the plug-ins, you also need to enable them and set them to automatically load to avoid restart failure.
Settings on the main library:
SET GLOBAL rpl_semi_sync_master_enabled = 1; SET GLOBAL rpl_semi_sync_master_timeout = 1000; -- Timeout time unit is milliseconds
You can also add in my.cnf
:
[mysqld] plugin_load_add='rpl_semi_sync_master=semisync_master.so' rpl_semi_sync_master_enabled=1 rpl_semi_sync_master_timeout=1000
Set from the library:
SET GLOBAL rpl_semi_sync_slave_enabled = 1;
Add the corresponding configuration file:
plugin_load_add='rpl_semi_sync_slave=semisync_slave.so' rpl_semi_sync_slave_enabled=1
After the setup is complete, restart the MySQL service to ensure that the plug-in takes effect.
Check status and operation status
Setting up does not mean that it takes effect immediately. You need to confirm that there is indeed a connection from the library in the replication topology to trigger semi-synchronous behavior.
You can use the following statement to see if it is currently in semi-synchronous:
SHOW STATUS LIKE 'Rpl_semi_sync_master_status';
If ON
is returned, it means that the current main library is using semi-synchronous mode; if OFF
, it may be that the slave library is not connected, or the slave library does not have the semi-synchronous plug-in enabled.
You can also see if the timeout occurs:
SHOW STATUS LIKE 'Rpl_semi_sync_master_no_times';
If this value continues to grow, it means that timeouts often occur, which may be delayed in network or stressed from the library.
Notes and FAQs
- Don't rely on only one slave library : Although semi-synchronously only has one slave library response, if that slave library goes down, the master library will automatically degenerate into asynchronous mode. If you want to keep semi-synchronous as possible, it is recommended to install multiple slave libraries.
- Reasonably set the timeout time : the default is 1 second (1000ms). Too short will lead to frequent degradation, and too long will affect the write response speed. It can be adjusted appropriately according to the network conditions.
- After switching between master and slave, you need to re-enable the plug-in : If the master and slave role changes, remember to enable the semi-synchronous plug-in on the new master library.
- Monitor the status of the plug-in : It is recommended to include the status of the plug-in in the monitoring item to prevent replication degradation due to the failure of the plug-in to start.
Basically that's it. Setting up is not complicated, but what is easy to ignore is whether the plug-in is really loaded, whether it is enabled correctly, and whether the timeout setting is reasonable. As long as you understand these points clearly, semi-synchronous replication can run stably.
The above is the detailed content of Setting up semi-synchronous replication in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MySQL needs to be optimized for financial systems: 1. Financial data must be used to ensure accuracy using DECIMAL type, and DATETIME is used in time fields to avoid time zone problems; 2. Index design should be reasonable, avoid frequent updates of fields to build indexes, combine indexes in query order and clean useless indexes regularly; 3. Use transactions to ensure consistency, control transaction granularity, avoid long transactions and non-core operations embedded in it, and select appropriate isolation levels based on business; 4. Partition historical data by time, archive cold data and use compressed tables to improve query efficiency and optimize storage.

TooptimizeMySQLforreal-timedatafeeds,firstchoosetheInnoDBstorageenginefortransactionsandrow-levellocking,useMEMORYorROCKSDBfortemporarydata,andpartitiontime-seriesdatabytime.Second,indexstrategicallybyonlyapplyingindexestoWHERE,JOIN,orORDERBYcolumns,

TosecureMySQLeffectively,useobject-levelprivilegestolimituseraccessbasedontheirspecificneeds.Beginbyunderstandingthatobject-levelprivilegesapplytodatabases,tables,orcolumns,offeringfinercontrolthanglobalprivileges.Next,applytheprincipleofleastprivile

When dealing with large tables, MySQL performance and maintainability face challenges, and it is necessary to start from structural design, index optimization, table sub-table strategy, etc. 1. Reasonably design primary keys and indexes: It is recommended to use self-increment integers as primary keys to reduce page splits; use overlay indexes to improve query efficiency; regularly analyze slow query logs and delete invalid indexes. 2. Rational use of partition tables: partition according to time range and other strategies to improve query and maintenance efficiency, but attention should be paid to partitioning and cutting issues. 3. Consider reading and writing separation and library separation: Read and writing separation alleviates the pressure on the main library. The library separation and table separation are suitable for scenarios with a large amount of data. It is recommended to use middleware and evaluate transaction and cross-store query problems. Early planning and continuous optimization are the key.

ToimproveMySQLperformanceforCMSplatformslikeWordPress,firstimplementacachinglayerusingpluginslikeRedisorMemcached,enableMySQLquerycaching(ifapplicable),andusepagecachingpluginstoservestaticfiles.Second,optimizeMySQLconfigurationbyincreasinginnodb_buf

MySQL replication filtering can be configured in the main library or slave library. The main library controls binlog generation through binlog-do-db or binlog-ignore-db, which is suitable for reducing log volume; the data application is controlled by replicate-do-db, replicate-ignore-db, replicate-do-table, replicate-ignore-table and wildcard rules replicate-wild-do-table and replicate-wild-ignore-table. It is more flexible and conducive to data recovery. When configuring, you need to pay attention to the order of rules, cross-store statement behavior,

DELETEremovesspecificorallrows,keepstablestructure,allowsrollbackandtriggers,anddoesnotresetauto-increment;2.TRUNCATEquicklyremovesallrows,resetsauto-increment,cannotberolledbackinmostcases,doesnotfiretriggers,andkeepstablestructure;3.DROPremovesthee

Check whether the MySQL service is running, use sudosystemctlstatusmysql to confirm and start; 2. Make sure that bind-address is set to 0.0.0.0 to allow remote connections and restart the service; 3. Verify whether the 3306 port is open, check and configure the firewall rules to allow the port; 4. For the "Accessdenied" error, you need to check the user name, password and host name, and then log in to MySQL and query the mysql.user table to confirm permissions. If necessary, create or update the user and authorize it, such as using 'your_user'@'%'; 5. If authentication is lost due to caching_sha2_password
