我对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;
如果有另一种方法可以做到这一点(可能没有使用游标,因为只返回了一行),这将是很棒的。
答案 0 :(得分: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 |
+-----+-------------+---------------------+---------+---------+-------+-----------------------------------------------------------------------+------------------+