MySQL has been reported to cause a few issues that go away when another arrive is used.
However, in your case you may simply asked to many commands in too short of a time. I have been running into similar issues with other bindings. Try to add a few ‘’’ thread::sleep(50)‘’’ statements in between the send commands (say every four or five statements ) and see if that makes it more reliable. The number in parenthesis is the time your rule will pause in milliseconds. But be careful to not make your rule taking too long in the end. See here as for the why