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. Labview实现单边带信号调制(SSB)[移相法]

    Labview实现单边带信号调制(SSB)[移相法] 时域上的表达式为 调制器模型为 这个实验中需要相位偏移比较多,因为一共用了四个信号仿真器,一个是无偏移的调制信号,一个是偏移的调制信号,一个是无偏 ...

  2. objective-c自学总结(三)---面向对象的封装,继承与多态

    面向对象的三大特性 封装 继承 多态 1.封装: 隐藏属性,方法或实现细节的过程称为封装 信息隐藏,隐藏对象的实现细节,不允许用户看到 将东西包装在一 然后以新的完整形式呈现出来 例如,两种或多种化学 ...

  3. 微软职位内部推荐-Sr SDE

    微软近期Open的职位: MSN reaches nearly half a billion people across the globe where we are the #1 portal in ...

  4. Hadoop TextInputFormat源码分析

    from:http://blog.csdn.net/lzm1340458776/article/details/42707047 InputFormat主要用于描述输入数据的格式(我们只分析新API, ...

  5. 玩耍Hibernate系列(二)--基础知识

    Hibernate思维导图   Hibernate映射 关于hibernate的映射要说明的一点就是关于ID的访问权限,peroperty以及field的区别: 表的主键在内存中对应一个OID对象描述 ...

  6. android 开发Parcelable 怎么传值ArrayList

    public class TradeEntity implements Parcelable{ public String id; //有关进度条的参数 ArrayList<TradeState ...

  7. javascript_04 数据类型

    ECMAScript 数据类型  标准  核心   数据类型 typeof  判断数据类型 数字型 布尔型 对象类型 函数 字符串 undefined 未定义 数字型  字符型 var s='1233 ...

  8. iOS开发如何实现消息推送机制

    一.关于推送通知 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序没有启动或不在前台运行时,告诉用户有新消息的一种途径,是从外部服务器发送到应用程序上的.一般说来,当要显示消息 ...

  9. if in hlsl

    seems that in HLSL_4, we can use if https://msdn.microsoft.com/en-us/library/bb313972(v=xnagamestudi ...

  10. skinned mesh 蜘蛛样

    被skinned mesh 折磨了 好久,开始感觉skinindices不对,因为pix显示里面全是0 后来跟来跟去发现是这样的,那些uchar的整数被pix用float的格式显示出来 (显示为0.0 ...