I’ve experienced similar issues when using MySQL databases. What you’re experiencing can most likely be linked to some kind of server problem. That’s what it’s boiling down to most of the time. One of my clients was having a real bad time with his database and I identified the faulty server as being the culprit behind most of the issues. Once we switched him up to a cloud server all of the connectivity problems were gone. Also, you could try using a service like Aiven for MySQL. With that you can connect appliances to your databases with ease. I hope I could help you, and you figure out the problems.