import MySQLdb
#pip install mysqlclient -i https://mirrors.aliyun.com/pypi/simple/
import time
def check_mysql_conn(conn):
    try:
        conn.ping()
        return True
    except:
        return False
if __name__ == '__main__':
    conn = MySQLdb.connect(
    host='localhost',
    user='root',
    port=3306,
    password='123456',
    charset="utf8",
    database='test'
    )
    while True:
        if not check_mysql_conn(conn):
            conn = MySQLdb.connect(
            host='localhost',
            user='root',
            port=3306,
            password='123456',
            charset="utf8",
            database='test'
            )
            print('reconnect mysql')
            time.sleep(60)