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.

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

4.命令

 SHOW VARIABLES LIKE 'AUTOCOMMIT';
SET AUTOCOMMIT = 1;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; -- These locking hints are frequently abused and should usually be avoided
SELECT ... LOCK IN SHARE MODE
SELECT ... FOR UPDATE LOCK TABLES
UNLOCK TABLES SHOW TABLE STATUS LIKE 'user' \G ALTER TABLE mytable ENGINE = InnoDB; mysql> CREATE TABLE innodb_table LIKE myisam_table;
mysql> ALTER TABLE innodb_table ENGINE=InnoDB;
mysql> INSERT INTO innodb_table SELECT * FROM myisam_table; mysql> START TRANSACTION;
mysql> INSERT INTO innodb_table SELECT * FROM myisam_table WHERE id BETWEEN x AND y;
mysql> COMMIT;

高性能MySQL笔记-第1章MySQL Architecture and History-001的更多相关文章

  1. 高性能MySQL笔记 第6章 查询性能优化

    6.1 为什么查询速度会慢   查询的生命周期大致可按照顺序来看:从客户端,到服务器,然后在服务器上进行解析,生成执行计划,执行,并返回结果给客户端.其中“执行”可以认为是整个生命周期中最重要的阶段. ...

  2. 高性能MySQL笔记 第5章 创建高性能的索引

    索引(index),在MySQL中也被叫做键(key),是存储引擎用于快速找到记录的一种数据结构.索引优化是对查询性能优化最有效的手段.   5.1 索引基础   索引的类型   索引是在存储引擎层而 ...

  3. Linux 笔记 - 第二十三章 MySQL 主从复制配置

    一.前言 MySQL Replication,也被称为主从复制.AB 复制.简单来说就是 A 和 B 两台服务器做主从后,在 A 服务器上写入数据,B 服务器上也会跟着写入输入,两者之间的数据是实时同 ...

  4. Mysql笔记之 -- replace()实现mysql 替换字符串

    mysql 替换函数replace()实现mysql 替换字符串 mysql 替换字符串的实现方法:  mysql中replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数 ...

  5. 高性能MySQL笔记 第4章 Schema与数据类型优化

    4.1 选择优化的数据类型   通用原则   更小的通常更好   前提是要确保没有低估需要存储的值范围:因为它占用更少的磁盘.内存.CPU缓存,并且处理时需要的CPU周期也更少.   简单就好   简 ...

  6. 高性能MySQL笔记-第5章Indexing for High Performance-004怎样用索引才高效

    一.怎样用索引才高效 1.隔离索引列 MySQL generally can’t use indexes on columns unless the columns are isolated in t ...

  7. 高性能MySQL笔记-第5章Indexing for High Performance-002Hash indexes

    一. 1.什么是hash index A hash index is built on a hash table and is useful only for exact lookups that u ...

  8. 高性能MySQL笔记-第5章Indexing for High Performance-001B-Tree indexes(B+Tree)

    一. 1.什么是B-Tree indexes? The general idea of a B-Tree is that all the values are stored in order, and ...

  9. 高性能MySQL笔记-第4章Optimizing Schema and Data Types

    1.Good schema design is pretty universal, but of course MySQL has special implementation details to ...

随机推荐

  1. WPF多窗口传参解决方案

    在WPF中,我们的常常涉及到多个窗口之间传递参数的问题,那么该怎么传呢? 答:在窗口的构造函数中添加想要传递的参数.(我表达不好,请看下面代码.) 在主窗口中单机button打开一个新的子窗口. // ...

  2. javascript学习小记(一)

    大四了,课少了许多,突然之间就不知道学什么啦.整天在宿舍混着日子,很想学习就是感觉没有一点头绪,昨天看了电影激战.这种纠结的情绪让我都有点喘不上气啦!一点要找点事情干了,所以决定找个东西开始学习.那就 ...

  3. R语言绘图002-页面布局

    par().layout().split.screen()函数 1. par()函数的参数详解 函数par()可以用来设置或者获取图形参数,par()本身(括号中不写任何参数)返回当前的图形参数设置( ...

  4. 关于EF查询的性能

    现象:前台grid发送ajax请求,通过谷歌devtool发现“waiting”时间高达23s(1500条数据);可见服务器端代码处理花费时间很长: 解决:分析代码,有两处代码注释掉后速度提升明显 / ...

  5. OpenFramework中视频或者图片进行中心旋转、平移、放大、缩小、矫正(本例以视频为准,只给出主要代码)

    /********** update mesh部分***********/ for(int i=0;i<4;i++) {  mesh[i].clear(); //重要,不加的话,移动视频的四个角 ...

  6. 使用WatchService监控指定目录内的文件的改动

    package coin; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Pat ...

  7. Python python 基本语法

    程序1 def buildConnectionString(params): """Build a connection string from a dictionary ...

  8. AutoMap1.0发布

    去年就已经透漏了AutoMap的雏形,后面一段时间一直没有充裕的时间来完成,只能零星的进行完善.现在产品还有很多不足,基本架构已经完成,就先释放一个1.0版,希望大家多多支持. 一.服务端 服务端在I ...

  9. FastDFS配置文件(storage.conf)

    # 该配置文件是否生效 # false:生效 # true:无效 disabled=false # 本storage server所属组名 group_name=group1 # 绑定IP # 后面为 ...

  10. IE 选择文字后 显示小箭头 加速按钮

    IE - 工具 - Internet选项 - 高级 - 不选择<在选择是显示加速按钮>选项就可以了.