Python-mysql-connector: cursor.fetch on stopped mysql slave fails

370 views Asked by At

I have searched for days to find the cause of this issue but with no luck, I have the following block of python code that should retrieve the status of the slave mysql server after it is stopped.
It works perfectly when the slave is running. However the craziest part is that when the slave is stopped, it returns the following error:

Failed getting warnings; MySQL Connection not available.

from this line:

print(len(crsr.fetchall()))

WHY?

conn = connectdb(hostname, dbuser, dbpass, dbname)
crsr = conn.cursor(dictionary=True)
crsr.execute("SHOW SLAVE STATUS")
print(len(crsr.fetchall()))
row = list(crsr.fetchall())[0]
slave_status = row['Slave_SQL_Running_State']
if slave_status is None:
    print("This is not a slave")
else:
    print(slave_status)

I have tried this locally on normal mysql and on mysql RDS instances:
python version 3.8.5
local mysql Ver 8.0.21 for Win64 on x86_64 (MySQL Community Server - GPL)
RDS mysql 5.7.28 for linux x64 (MySQL Community Server - GPL)

0

There are 0 answers