2

我对 mysql 存储过程相当陌生,我需要能够从过程中访问 SHOW SLAVE STATUS 的结果。我在网上搜索但似乎无法找到它。这是我一直在尝试的事情:

    CREATE PROCEDURE test()
BEGIN
 DECLARE a VARCHAR(1000);
 DECLARE cur1 CURSOR FOR SHOW SLAVE STATUS;
 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

 OPEN cur1;

 read_loop: LOOP
  FETCH cur1 INTO a;
  IF done THEN
   LEAVE read_loop;
  END IF;
 END LOOP;

 SELECT a;

 CLOSE cur1;
END;

这失败了,原因如下:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SHOW SLAVE STATUS;
 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

如果有另一种方法可以做到这一点(可能不使用游标,因为只有一行返回),那就太好了。

4

1 回答 1

2

以防万一其他人有这个问题。

我找到了一个肮脏的方法。我没有得到我需要的所有信息,但这是一个开始。

information_schema.processlist(或SHOW PROCESSLIST)具有我可以在存储过程中使用的从属进程:

+-----+-------------+---------------------+---------+---------+-------+-----------------------------------------------------------------------+------------------+
| Id  | User        | Host                | db      | Command | Time  | State                                                                 | Info             |
+-----+-------------+---------------------+---------+---------+-------+-----------------------------------------------------------------------+------------------+
|   1 | system user |                     | NULL    | Connect | 75212 | Waiting for master to send event                                      | NULL             |
|   2 | system user |                     | NULL    | Connect |  2158 | Has read all relay log; waiting for the slave I/O thread to update it | NULL             |
+-----+-------------+---------------------+---------+---------+-------+-----------------------------------------------------------------------+------------------+
于 2012-06-14T11:37:29.290 回答