MySQL behaviour on connection failure

MySQLtransaction

My MySQL database is hosted on a different machine from my application system, which issues queries to the MySQL database remotely.

If for some reason the network connection between the two machines break, while a query was being processed, what will happen?

I suspect that MySQL will reject any garbage data but I don't want it to save that garbage data in my rows and I don't want MySQL to get stuck.

Best Answer

You have to understand that the underlying protocol that you're using to send dta(http://en.wikipedia.org/wiki/Transmission_Control_Protocol). The TC-Protocol is designed to deal with network breaks. Ultimately if you send a transmission to the remote server saying, for instance "insert into table (id, name) values (1, 'test');" then the TC-Protocol will handle not only delivering it, but also making sure it arrives in tact. In fact, it will even retry... but if there's a persistent network break it'll tell your application that the connection to the remote server was lost.

Thus, the answer is simply you do not need to do anything about this. TCP will make sure you don't get garbage data. TCP is the reason that you do not see garbage web-pages when you are on a shoddy connection. It also makes sure that you don't deliver garbage to your DB's.

We run about 500 million transactions a month into the DB and not one are garbage - because of TCP.