What is MySQL's transaction and implementation

Source: Internet
Author: User
Tags ming

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.