Home > Database > Mysql Tutorial > body text

mysql的事宜运作

WBOY
Release: 2016-06-07 16:24:56
Original
966 people have browsed it

mysql的事务运作 mysql的事务运作 早就想写了,一直忘了,其实很简单 就三条命令 start transaction commit rollback 现在来解释下: start transaction; 就是开始事务追踪的命令 开始前一定记得写 然后 commit; 这个的意思是说确认提交,执行这个命令就不能r

mysql的事务运作

mysql的事务运作

早就想写了,一直忘了,其实很简单

  1. 就三条命令

    start transaction
    commit
    rollback

  2. 现在来解释下:

    start transaction;
    就是开始事务追踪的命令
    开始前一定记得写

    然后

    commit;
    这个的意思是说确认提交,执行这个命令就不能rollback了,相当于执行完毕。

    最后

    rollback;
    这个命令很简单,回滚到start transaction时候的状态

  3. 现在举例
    mysql> select * from useraccount ;
    +-----------+--------+-------------+
    | AccountID | userID | AccountName |
    +-----------+--------+-------------+
    | 1 | 2 | zhifubao |
    +-----------+--------+-------------+
    1 row in set (0.00 sec)

    mysql> start transaction;
    Query OK, 0 rows affected (0.00 sec)

    mysql> update useraccount set userID = 1;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1 Changed: 1 Warnings: 0

    mysql> select * from useraccount;
    +-----------+--------+-------------+
    | AccountID | userID | AccountName |
    +-----------+--------+-------------+
    | 1 | 1 | zhifubao |
    +-----------+--------+-------------+
    1 row in set (0.00 sec)

    mysql> rollback; (这里假如不想回滚就用commit;就可以完成了)
    Query OK, 0 rows affected (0.28 sec)

    mysql> select * from useraccount;
    +-----------+--------+-------------+
    | AccountID | userID | AccountName |
    +-----------+--------+-------------+
    | 1 | 2 | zhifubao |
    +-----------+--------+-------------+
    1 row in set (0.00 sec)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template