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 le…
6.1 为什么查询速度会慢   查询的生命周期大致可按照顺序来看:从客户端,到服务器,然后在服务器上进行解析,生成执行计划,执行,并返回结果给客户端.其中“执行”可以认为是整个生命周期中最重要的阶段.这其中包括了大量为了检索数据到存储引擎的调用以及调用后的数据处理,包括排序.分组等.   在完成这些任务时,查询需要在不同的地方花费时间,包括网络.CPU计算.生成统计信息和执行计划.锁等待等操作,尤其是向底层存储引擎检索数据的调用操作,这些调用需要在内存操作.CPU操作和内存不足时导致的IO操作上…
索引(index),在MySQL中也被叫做键(key),是存储引擎用于快速找到记录的一种数据结构.索引优化是对查询性能优化最有效的手段.   5.1 索引基础   索引的类型   索引是在存储引擎层而不是服务器层实现的.所以,并没有统一的索引标准:   B-Tree 索引   不同的存储引擎以不同的方式使用B-Tree索引,性能也各有不同:例如,MyISAM使用前缀压缩技术使得索引更小,而InnoDB则按照原数据格式进行存储.再如MyISAM索引通过数据的物理位置引用被索引的行,而InooDB则…
一.前言 MySQL Replication,也被称为主从复制.AB 复制.简单来说就是 A 和 B 两台服务器做主从后,在 A 服务器上写入数据,B 服务器上也会跟着写入输入,两者之间的数据是实时同步的.主从复制技术主要用来提供实时备份或读写分离服务. MySQL 主从是基于 binlog 的,主服务器必须开启 binlog 才能进行主从复制.主从复制过程大致有如下三个步骤. 1)主服务器将更改操作记录到 binlog 中. 2)从服务器将主的 binlog 事件(SQL 语句)同步到本机上并…
mysql 替换函数replace()实现mysql 替换字符串 mysql 替换字符串的实现方法:  mysql中replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数去替换,用起来非常的方便. mysql 替换函数replace() UPDATE `table_name` SET `field_name` = replace (`field_name`,'from_str','to_str') WHERE `field_name` LIKE '%from_str…
4.1 选择优化的数据类型   通用原则   更小的通常更好   前提是要确保没有低估需要存储的值范围:因为它占用更少的磁盘.内存.CPU缓存,并且处理时需要的CPU周期也更少.   简单就好   简单数据类型的操作需要更少的CPU周期.   尽量避免NULL   值可为NULL的列使得索引.索引统计和值比较都更复杂化.可为NULL的列会使用更多的存储空间.   整数类型   TINYINT SMALLINT MEDIUMINT INT BIGINT.分别使用8,16,24,32,64位存储空间…
一.怎样用索引才高效 1.隔离索引列 MySQL generally can’t use indexes on columns unless the columns are isolated in the query. “Isolating” the column means it should not be part of an expression or be inside a function in the query. 如,以下的查询不能用actor_id索引 SELECT actor_…
一. 1.什么是hash index A hash index is built on a hash table and is useful only for exact lookups that use every column in the index. For each row, the storage engine computes a hash code of the indexed columns, which is a small value that will probably…
一. 1.什么是B-Tree indexes? The general idea of a B-Tree is that all the values are stored in order, and each leaf page is the same distance from the root. A B-Tree index speeds up data access because the storage engine doesn’t have to scan the whole tab…
1.Good schema design is pretty universal, but of course MySQL has special implementation details to consider. In a nutshell, it’s a good idea to keep things as small and simple as you can. MySQL likes simplicity, and so will the people who have to wo…