2/19
补充:MySQL事务隔离级别
读未提交:一个事务可以读取到,另外一个事务尚未提交的变更。
读已提交:一个事务提交后,其变更才会被另一个事务读取到。
可重复读:在一个事务执行的过程中所读取到的数据,和事务启动时所看到的一致。
会话一
mysql> delete from test;
Query OK, 3 rows affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.01 sec)
会话2
mysql> set session transaction isolation level REPEATABLE read;
Query OK, 0 rows affected (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+------+
| id |
+------+
| 1 |
| 1 |
| 1 |
+------+
3 rows in set (0.00 sec)
mysql> select * from test;
+------+
| id |
+------+
| 1 |
| 1 |
| 1 |
+------+
3 rows in set (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
Empty set (0.00 sec)
测试过程中:二会话设置可重复性读之后,开启一个事务,在事务中获取的数据完全和事务开启时读取的数据是一样的,无论
在事务过程中,别的事务有对数据进行更改提交都不会影响
串行化:当操作一行数据时,读写分别都会加锁。当出现读写锁互斥时,会排队串行执行。
原理
怎么拿到一致性备份?什么是一致性备份
一致性备份:所有的表都在一个时间点,起始一个时间点,
mysqldump过程?(备份开始的时间是相同的)
1.flush tables (将数据库的表都close,能拿到全局的数据)-->MDL全局级的(将内存中的数据刷人表中)
2.flush table with read lock--->只读状态(实例级别)
3.set session transaction isolation level repeateble read;(开启一个事务,一致性读,可重复读)
4.start transaction(起始点)
5.show master status;(实例目前不能写入)全局级的
6.ulock tables(数据库可以写入)
7.show create database wubx;
8.savepoint sp; (事务内的断点)
9.show create table wubx;备份表结构
10.select * from wubx;备份数据
11.rollback to savepoint sp
next tb
....
release savepoint sp
过程展示:
准备工作开启general log 记录备份过程
mysql> set global general_log=1;
Query OK, 0 rows affected (1.66 sec)
mysql> show variables like '%gener%';
+------------------+-------------+
| Variable_name | Value |
评论