博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
高性能MySQL笔记-第1章MySQL Architecture and History-001
阅读量:4561 次
发布时间:2019-06-08

本文共 3588 字,大约阅读时间需要 11 分钟。

1.MySQL架构图

 

2.事务的隔离性

事务的隔离性是specific rules for which changes are and aren’t visible inside and outside a transaction

(1)READ UNCOMMITTED

In the READ UNCOMMITTED isolation level, transactions can view the results of uncommitted transactions. At this level, many problems can occur unless you really,really know what you are doing and have a good reason for doing it. This level is rarely used in practice, because its performance isn’t much better than the other levels, which have many advantages. Reading uncommitted data is also known as a dirty read.

(2)READ COMMITTED

The default isolation level for most database systems (but not MySQL!) is READ COMMITTED . It satisfies the simple definition of isolation used earlier: a transaction will see only those changes made by transactions that were already committed when it began, and its changes won’t be visible to others until it has committed.This level still allows what’s known as a nonrepeatable read. This means you can run the same statement twice and see different data.

(3)REPEATABLE READ

REPEATABLE READ solves the problems that READ UNCOMMITTED allows. It guarantees that any rows a transaction reads will “look the same” in subsequent reads within the same transaction, but in theory it still allows another tricky problem: phantom reads. Simply put, a phantom read can happen when you select some range of rows,another transaction inserts a new row into the range, and then you select the same range again; you will then see the new “phantom” row. InnoDB and XtraDB solve the phantom read problem with multiversion concurrency control, which we explain later in this chapter.

REPEATABLE READ is MySQL’s default transaction isolation level.

(4)SERIALIZABLE

The highest level of isolation, SERIALIZABLE , solves the phantom read problem by forcing transactions to be ordered so that they can’t possibly conflict. In a nutshell,SERIALIZABLE places a lock on every row it reads. At this level, a lot of timeouts and lock contention can occur. We’ve rarely seen people use this isolation level, but your application’s needs might force you to accept the decreased concurrency in favor of the data stability that results.

 

3.为什么会产生死锁?

当不同的事务请求同一资源,发生循环引用时,就会产生死锁。A deadlock is when two or more transactions are mutually holding and requesting locks on the same resources, creating a cycle of dependencies. Deadlocks occur when transactions try to lock resources in a different order.

1 Transaction #1 2 START TRANSACTION; 3 UPDATE StockPrice SET close = 45.50 WHERE stock_id = 4 and date = '2002-05-01'; 4 UPDATE StockPrice SET close = 19.80 WHERE stock_id = 3 and date = '2002-05-02'; 5 COMMIT; 6 Transaction #2 7 START TRANSACTION; 8 UPDATE StockPrice SET high = 20.12 WHERE stock_id = 3 and date = '2002-05-02'; 9 UPDATE StockPrice SET high = 47.20 WHERE stock_id = 4 and date = '2002-05-01';10 COMMIT;

 

 

4.命令

1 SHOW VARIABLES LIKE 'AUTOCOMMIT'; 2 SET AUTOCOMMIT = 1; 3 SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; 4  5 -- These locking hints are frequently abused and should usually be avoided 6 SELECT ... LOCK IN SHARE MODE 7 SELECT ... FOR UPDATE 8  9 LOCK TABLES  10 UNLOCK TABLES11 12 SHOW TABLE STATUS LIKE 'user' \G13 14 ALTER TABLE mytable ENGINE = InnoDB;15 16 mysql> CREATE TABLE innodb_table LIKE myisam_table;17 mysql> ALTER TABLE innodb_table ENGINE=InnoDB;18 mysql> INSERT INTO innodb_table SELECT * FROM myisam_table;19 20 mysql> START TRANSACTION;21 mysql> INSERT INTO innodb_table SELECT * FROM myisam_table WHERE id BETWEEN x AND y;22 mysql> COMMIT;

 

转载于:https://www.cnblogs.com/shamgod/p/5348249.html

你可能感兴趣的文章
2-sat 问题 【例题 Flags(2-sat+线段树优化建图)】
查看>>
ext3.2 右击动态添加node的treepanel
查看>>
Database links
查看>>
数据库事务
查看>>
xe7 控件升级
查看>>
TFrame bug
查看>>
刚学习的如何才能自信的拍美美的婚纱照呢(要结婚啦)
查看>>
M51文件注释
查看>>
关于临界资源访问互斥量的死锁问题
查看>>
django-view层
查看>>
异步加载JS的方法。
查看>>
golang-gorm框架支持mysql json类型
查看>>
【tool】白盒测试
查看>>
Linux 下的 scp
查看>>
理解同步,异步和延迟脚本
查看>>
Checklist: 2019 05.01 ~ 06.30
查看>>
Binary XML file : Error inflating class com.esri.android.map.MapView
查看>>
grep,awk和sed
查看>>
.NET Core WebAPI IIS 部署问题
查看>>
SystemTap 静态探针安装包
查看>>