mysql MASTER_POS_WAIT function

grammar

select master_pos_wait(file, pos[,   timeout]).

 

File  and pos  is a value corresponding to the main library, you can show master status  obtained.

Timeout  is the number of seconds to wait. Without representatives, returns the result immediately. If you specify a time, but has reached the position  , it will still return immediately. That is, waiting for events from the library does not reach the designated position  to take effect.

 

This function is mainly used to perform from the library to see if the library has been performed to the main library on the specified binlog position  .

 

Main library View

mysql> show binary logs;

+------------------+-----------+

| Log_name         | File_size |

+------------------+-----------+

| mysql-bin.000001 |  51635123 |

+------------------+-----------+

1 row in set (0.00 sec)

 

Execution from the 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)

返回值为,代表从库已经应用了mysql-bin.000001 51635123 位置的数据。

 

下面将pos 值加1

mysql> SELECT MASTER_POS_WAIT('mysql-bin.000001',   51635124);

一直在等待,不返回结果。

主库执行一个事务后,pos 肯定超越了51635124 ,从库应用后返回结果,如下:

+-----------------------------------------------+

| MASTER_POS_WAIT('mysql-bin.000001',   51635124) |

+-----------------------------------------------+

|                                             1 |

+-----------------------------------------------+

1 row in set (50.66 sec)

 

从库pos+1 ,这次指定时间为,五秒后未达到,返回-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)

 

从库执行stop slave sql_thread; 返回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)

 郑州不孕不育医院:http://jbk.39.net/yiyuanzaixian/zztjyy/

Action

Return

无论是否指定时间,达到

0

指定时间内达到

1

指定时间内未达到

-1

stop slave sql_thread;

NULL


Guess you like

Origin blog.51cto.com/14510351/2437069