mysql的使用21

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> #隔离级别
mysql> #如果用户想要在mysql启动时就设置事务的默认隔离级别,那就需要修改mysql的配置文件,在mysqlld中添加如下行:
mysql> $transaction-isolation = READ-COMMITTED
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$transaction-isolation = READ-COMMITTED' at line 1
mysql> #transaction-isolation = READ-COMMITTED
mysql>
mysql> #查看当前的会话的事务隔离级别
mysql> select @@tx_isolation;
+-----------------+
| @@tx_isolation  |
+-----------------+
| REPEATABLE-READ |
+-----------------+
1 row in set (0.00 sec)

mysql> #查看全局的
mysql> select @@global.tx_isolation;
+-----------------------+
| @@global.tx_isolation |
+-----------------------+
| REPEATABLE-READ       |
+-----------------------+
1 row in set (0.00 sec)

mysql> #分布式事务编程
mysql> #innodb存储引擎提供了对于xa事务的支持,并通过xa事务来支持分布式事务的实现,分布式事务指的是允许许多独立的事务资源参与到一个全局的事务中
mysql> #分布式事务使用两段式提交的方式,在第一阶段,所有参与全局事务的节点都开始准备,告诉事务管理器他们准备号提交了,第二个阶段,事务管理器告诉资源管理器rollbakc还是commit,如果任何一个节点显示不能提交,所有的节点都告知需要回滚
mysql>
mysql> create table aa(a int);
Query OK, 0 rows affected (0.10 sec)

mysql> xa start 'a';
Query OK, 0 rows affected (0.01 sec)

mysql> insert into aa select 11;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> xa end 'a';
Query OK, 0 rows affected (0.00 sec)

mysql> xa prepare 'a';
Query OK, 0 rows affected (0.03 sec)

mysql> xa recover;
+----------+--------------+--------------+------+
| formatID | gtrid_length | bqual_length | data |
+----------+--------------+--------------+------+
|        1 |            1 |            0 | a    |
+----------+--------------+--------------+------+
1 row in set (0.00 sec)

mysql> xa commit 'a';
Query OK, 0 rows affected (0.03 sec)

mysql> #单个节点上运行xa事务的例子
mysql>
mysql> #通过innodb_support_xa可以查看是否对xa事务的支持
mysql>
mysql> show variables like 'innodb_support_xa';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| innodb_support_xa | ON    |
+-------------------+-------+
1 row in set (0.00 sec)

mysql> #设置自动提交
mysql> set autocommit=0;
Query OK, 0 rows affected (0.01 sec)

mysql> set autocommit=1;
Query OK, 0 rows affected (0.00 sec)

mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)

mysql> #长事务:
mysql> #就是需要执行时间比较长的事务,例如银行系统的数据库,每过一个阶段都需要更新对应账户的利息,如果数量非常大,加入有一个亿  需要执行下列的语句
mysql> #update account set account_total = account_total+(1+inetrest_rate);
mysql> exit
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值