mSQL a regression test of a transaction, you can self-examine and understand the next transaction.
For example: Xiao Ming and small fly two people now have ¥100 in hand, suddenly small flying head of the problem said to Xiaoming ¥50, now they hand money is (Xiao Ming: ¥150, small fly: ¥50); So synchronization is the completion of a transaction, the following is the demo
/*
Transaction ACID
Atomicity of Atomic
Conformance consistency
Isolation isolation
Persistent durability
*/
var mysql = require (' mysql '); var connection = Mysql.createconnection ({ host: ' localhost ', User: ' Root ', Password: ', database: ' Yudi '}); Connection.connect ();//Start a transaction connection.begintransaction (function (err) { if (err) throw err; Connection.query (' Update account1 set mny=0 where id=1 ', function (err,results) { if (err) { Connection.rollback (function () { throw err; }) throw err; } Connection.query (' Update account2 set mny=200 where id=1 ', function (err,results) { if (err) {//rollback a thing Connection.rollback (function () { throw err;}) throw err;} Commit a thing connection.commit (function (err) { if (err) { connection.rollback () (function () { throw err; }) throw err;} Console.log (' success ');});})
What is MySQL's transaction and implementation