Mysql MASTER_POS_WAIT function
syntax
select master_pos_wait(file, pos[, timeout]).
File and pos are the corresponding master library values, which can be obtained by showing master status.
Timeout is the number of seconds to wait. 0, immediately returns the result. If the time is specified, but the position has been reached, it will return immediately. That is, wait for the event to take effect until the slave library does not reach the specified position.
This function is mainly used to check whether the slave library has been executed to the specified binlog position on the master library.
Master Library View
mysql> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 51635123 |
+------------------+-----------+
1 row in set (0.00 sec)
Executing from Library:
mysql> SELECT MASTER_POS_WAIT(' mysql-bin.000001', 51635123,60);
+--------------------------------------------------+
| MASTER_POS_WAIT('mysql-bin.000001', 51635123,60) |
+--------------------------------------------------+
| 0 |
+--------------------------------------------------+
1 row in set (0.00 sec)
A return value of 0 indicates that the data at position mysql-bin.000001 51635123 has been applied from the library.
Add 1 to the pos value
mysql> SELECT MASTER_POS_WAIT('mysql-bin.000001', 51635124);
They wait and do not return results.
After the main library executes a transaction, pos must exceed 51635124, and the result 1 is returned after the application from the library, as follows:
+-----------------------------------------------+
| MASTER_POS_WAIT('mysql-bin.000001', 51635124) |
+-----------------------------------------------+
| 1 |
+-----------------------------------------------+
1 row in set (50.66 sec)
From library pos+1, this time the specified time is 5, 5 seconds later does not reach, return-1
mysql> SELECT MASTER_POS_WAIT('mysql-bin.000001', 51635390,5);
+-------------------------------------------------+
| MASTER_POS_WAIT('mysql-bin.000001', 51635390,5) |
+-------------------------------------------------+
| -1 |
+-------------------------------------------------+
1 row in set (5.00 sec)
Execute stop slave sql_thread from the library; returns null
mysql> SELECT MASTER_POS_WAIT('mysql-bin.000001', 51635390,60);
+--------------------------------------------------+
| MASTER_POS_WAIT('mysql-bin.000001', 51635390,60) |
+--------------------------------------------------+
| NULL |
+--------------------------------------------------+
1 row in set (2.32 sec)
Zhengzhou infertility hospital: jbk.39.net/yiyuanzaixian/zztjyy/
Action
Return
Whether or not a specified time is reached
0
within specified time
1
Not reached within specified time
-1
stop slave sql_thread;
NULL