MySQL 8 Cookbook 阅读笔记

Performing transactions

ACID

Isolation levels

修改隔离级别

SET @@transaction_isolation = 'READ-COMMITTED';

mysql默认的事务隔离级别为Repeatable read

四种隔离级别

Read Uncommitted

Read Committed

Repeatable Read

Serializable

事务隔离级别为串行化时,读写数据都会锁住整张表

补充

Locking

Internal LocK

External Lock

Performance Turning

The explain plan

mysql > EXPLAIN SELECT * FROM ...

Benchmarking queries and the server

shell> mysqlslap -u <user> -p<pass> --query="SELECT ..."

Adding indexes

索引被使用的地方:

添加索引

mysql> ALTER TABLE employees ADD INDEX index_last_name(last_name);

Invisible indexes

mysql> ALTER TABLE employees ALTER INDEX last_name INVISIBLE;

Analyzing slow queries using pt-query-digest

Optimizing datatypes

Removing duplicate and redundant indexes

Checking index usage

Controlling the query optimizer

Using index hints

Indexing for JSON using generated columns

Using resource groups

Using performance schema

Using the sys schema

Written on January 30, 2019