Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know MySQL replication status using a select query?

Is it possible to get replication status from any system database table?

Using which I can identify whether the replication is up or down.

I need to to know whether the SLAVE_IO_RUNNING and SLAVE_SQL_RUNNING = YES from a system table.

like image 486
MySQL DBA Avatar asked Aug 10 '11 10:08

MySQL DBA


People also ask

How can I tell if SQL server replication is enabled?

Connect to the Publisher in Management Studio, and then expand the server node. Expand the Replication folder, and then expand the Local Publications folder. Expand the publication for the subscription you want to monitor. Right-click the subscription, and then click View Synchronization Status.

Is MySQL replication push or pull?

Each replica that connects to the source requests a copy of the binary log. That is, it pulls the data from the source, rather than the source pushing the data to the replica.

Is MySQL replication real time?

MySQL is a widely used Database by big organizations to run their business activities. Data replication is one such technique that allows users to access data from numerous sources such as servers, sites, etc. in real-time.

What is MySQL replication?

Replication enables data from one MySQL database server (known as a source) to be copied to one or more MySQL database servers (known as replicas). Replication is asynchronous by default; replicas do not need to be connected permanently to receive updates from a source.


2 Answers

This is the statement that I have used based on Manasi's top answer.

SELECT variable_value 
FROM information_schema.global_status 
WHERE variable_name='SLAVE_RUNNING';
like image 199
hslakhan Avatar answered Sep 19 '22 15:09

hslakhan


hslakhan's answer works for MySQL 5.6, but for MySQL 5.7 the slave status variables have moved from information_schema to performance_schema.

Slave_IO_Running corresponds to:

SELECT SERVICE_STATE FROM performance_schema.replication_connection_status;

Slave_SQL_Running corresponds to:

SELECT SERVICE_STATE FROM performance_schema.replication_applier_status;

There are some other variables from the SHOW SLAVE STATUS output too, see https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_show_compatibility_56_slave_status for the rest.

like image 38
Paul Tobias Avatar answered Sep 20 '22 15:09

Paul Tobias