1

Is there any way through which can I store my "show slave status" output into any permanent/temporary table. After storing output into table I will took some decisions against their error number.

2
  • Yes, see this question and its answers for ideas. As you can see you can do the equivalent of SHOW SLAVE STATUS with SELECT queries, so you may not even need a special table of your own, unless you want to log historic values.
    – dbdemon
    Commented Apr 27, 2018 at 17:06
  • I want to get value against "Last_Errno" column. above link is not providing this kind of information.
    – Irfi
    Commented May 2, 2018 at 7:33

1 Answer 1

2

Disclaimer: The below solution is probably unnecessarily complicated - the obvious solution to this would perhaps involve a cron job or maybe a database event running at some interval to execute SHOW SLAVE STATUS; and extracting the output into your table.

Nevertheless, here is what I think is an interesting solution which gives you instant access to the SHOW SLAVE STATUS output through a SELECT query. However, I've only been tested this with MariaDB (version 10.1.32), and it may or may not be portable to MySQL. It requires the CONNECT storage engine, and I'm not sure you can get that for MySQL.

First install the connect storage engine package in your OS. Then in the mysql client:

INSTALL SONAME 'ha_connect';
CREATE DATABASE IF NOT EXISTS `_` 
  DEFAULT CHARACTER SET = 'utf8' 
  DEFAULT COLLATE = 'utf8_general_ci';
USE _
CREATE OR REPLACE SERVER `_` 
  FOREIGN DATA WRAPPER MYSQL OPTIONS ( 
    HOST 'localhost', 
    USER 'root', PASSWORD 'your_password_here', 
    PORT 3306, 
    DATABASE '_' 
  )
;
CREATE TABLE show_slave_status 
  ENGINE = CONNECT 
  TABLE_TYPE = MYSQL 
  SRCDEF = 'SHOW SLAVE STATUS' 
  CONNECTION = '_';

Now you can get all the values you usually get from SHOW SLAVE STATUS with a SELECT: SELECT * FROM _.show_slave_status;

Credits: I borrowed almost all of this from Federico Razzoli's materialize.sql.

1
  • I know this thread is old, but i was wondering if there is any CONNECT storage engine - similar for MySQL (Percona or Oracle Community). The one you reported is for mariaDB
    – B3S
    Commented Sep 11, 2019 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.