我对 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;
如果有另一种方法可以做到这一点(可能不使用游标,因为只有一行返回),那就太好了。