当前位置:网站首页>After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
2022-07-02 17:23:00 【Jue seconds of writing code】
One 、 Preface
MySQL Tuning for many programmers , It's a very difficult problem , Most of the cases are due to the database problems and processing ideas are not clear . It's going on MySQL Before optimization, we must know that MySQL Query process of , A lot of query optimization work actually follows some principles MySQL The optimizer of can run as expected .
Just yesterday, I took time out of my busy schedule to interview a full stack developer from Tencent , I said it :MYSQL How to start with performance tuning ? His answer is : Based optimization 、 Philosophy of optimization 、 Optimize requirements 、 Optimization ideas 、 Storage engine layer 、 Database optimization 、 Wait for the details , Well, I admit I lost .
But I seriously doubt that he came prepared , Otherwise, no one can remember so clearly and orderly , Sure enough , He told the truth after he took office ;
There is a book recommended by many bosses in their team 【MySQL Performance optimization and high availability architecture practices 】 file

Well, don't say more , Xiaobian shares it directly , After learning, you can also write on your resume “ Master MySQL performance optimization ”, At the same time, I hope you can hang and beat other interviewers ;
Catalog
- InnoDB Storage cited the entire architecture
- MySQL Transactions and locks
- SLQ Language performance optimization

- MySQL Server optimization
- MySQL Performance monitoring
- MySQL Master slave copy
- PXC Highly available solutions

- be based on MHA Realized MySQL. Auto fail over cluster
- MySQL Group Replication
- Keepalived+ High availability architecture of dual master replication
- Database sub database sub table and middleware introduction
- Mycat Middleware details

MySQL Architecture introduction

The current industry MySQL Mainstream branch versions have Oracle The official version of MySQL、 Percona Server、MariaDB. Next, let's look at the characteristics of each branch .

InnoDB Storage engine architecture

from MySQL 5.5 Version start ,InnoDB Is the default table storage engine , It is characterized by supporting transactions 、 Support data row lock 、 the Multi version concurrency MVCC、 Support foreign keys .InnoDB The architecture of the storage engine is shown in the figure 2-1 Shown , Including memory pool 、 Background thread and underlying data file


MySQL Transactions and locks

MySQL Transaction isolation level
Transactions also satisfy isolation through the locking mechanism . stay InnoDB In the storage engine , There are different levels of isolation , They have different isolation .

Lock wait
Lock waiting refers to the lock generated during a transaction , Other transactions need to wait for the previous transaction to release its lock to occupy the resource . If the transaction has not been released , You need to keep waiting , Until the lock waiting time is exceeded , An error of waiting timeout will be reported . stay MySQL Pass through innodb_lock_wait_timeout Parameter to control the lock waiting time , The unit is seconds . Pictured 3-9 Shown , You can do this by saying show variables like '%innodb_lock_wait%' To see the lock wait timeout .

SQL Sentence performance optimization

Speaking of SQL Sentence performance optimization , I believe everyone knows some simple skills : Don't use SELECT *、 Don't use NULL Field 、 Using indexes properly 、 Select the appropriate data type for the field, etc . Do you really understand these optimization techniques ? Do you understand how it works ? This chapter starts from the perspective of theory and practice , Explain the principles behind these optimization suggestions .

Create high-performance indexes
The index is to improve MySQL An important way to query performance . Try to avoid thinking about adding indexes afterwards , Because you may need to monitor a lot of SQL To locate the problem , And the time needed to increase the index must be much longer than the time needed to increase the index initially .

MySQL Server comprehensive optimization

Most use Linux Large and medium-sized Internet websites with operating systems are using MySQL As a back-end database service , So how to optimize MySQL Server is what we want to study . Now? MySQL 5.7 Version for multi-core CPU、 Solid state disk 、 The lock mechanism has better optimization . in addition ,MySQL 5.7 The version has improved the optimizer a lot , such as MySQL 5.7 Of in Sentence query can use index range scan The way ,Union all No more temporary tables , Sorting efficiency has also been improved . We from MySQL 5.7 Version of the storage engine enhancements , Hardware 、 operating system 、 Configuration parameter optimization 、 The design specification is optimized in several aspects MySQL The server

MySQL Performance monitoring

MySQL Accepted by more and more enterprises . With the development of the enterprise ,MySQL Storage data is expanding , Performance analysis 、 Monitoring and early warning is very important . In some cases , Usually a set of MySQL monitor / Graphical tools , And then according to MySQL Monitor the information provided by the panel to perform further tuning .


MySQL Master slave copy

MySQL The master-slave replication function of is built on MySQL High availability of database 、 High performance application foundation , It can be used to share the read load of the main database , It is also highly available HA And so on . Master-slave replication means that data can be copied from one MySQL The database server master node replicates to another one or more MySQL Database server slave node . Master slave replication can be used for real-time data backup 、 Read / write separation 、 High availability HA And so on .


PXC Highly available solutions



be based on MHA Realized MySQL Auto fail over cluster

MHA It's an excellent set of actions MySQL High availability software for failover and master-slave promotion in high availability environment . It's made up of two parts :MHAManager( The management node ) and MHA Node( Data nodes ), Pictured 9-1 Shown .MHA Manager Can be independently deployed on a separate machine to manage multiple master-slave Primary and secondary replication clusters , It can also be deployed in one slave From the node .

MySQL Group Replication

For a long time MySQL Officials lack native MySQL Clusters are flexible and can provide solutions with strong consistency , So third party companies are based on Galera Agreed Percona XtraDB Cluster(PXC) Accumulated many customer cases . 2016 year 12 month 12 Japan Oracle Released MySQL Group Replication The first of GA edition , And provide their own comparison Galera Performance testing .MGR As a star product promoted by the government , Indeed, it has the same old brand products as the market ( Such as PXC) Eligibility for competition .MGR Is based on Paxos High availability solution of distributed consistency protocol , Perfectly solved MySQL Defects in consistency and high availability . future MGR The probability of the plan will become the bank 、 insurance 、 High availability and disaster recovery solutions for financial services such as securities .


Keepalived+ High availability architecture of dual master replication


All right, that's it , I hope the little partner who gets this document can cut down his favorite offer
边栏推荐
- 剑指 Offer 24. 反转链表
- Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
- 剑指 Offer 25. 合并两个排序的链表
- 剑指 Offer 26. 树的子结构
- Sword finger offer 22 The penultimate node in the linked list
- 剑指 Offer 27. 二叉树的镜像
- Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
- Explanation of traceroute command
- 福元医药上交所上市:市值105亿 胡柏藩身价超40亿
- Briefly introduce the use of base64encoder
猜你喜欢

使用知行之桥的API端口,提供资源供合作伙伴访问
![[shutter] dart data type (dynamic data type)](/img/6d/60277377852294c133b94205066e9e.jpg)
[shutter] dart data type (dynamic data type)

TCP拥塞控制详解 | 2. 背景

剑指 Offer 22. 链表中倒数第k个节点

QWebEngineView崩溃及替代方案

綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東

一文看懂:数据指标体系的4大类型

871. Minimum refueling times

A case study of college entrance examination prediction based on multivariate time series

Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
随机推荐
【Leetcode】13. 罗马数字转整数
Schoolbag novel multithreaded crawler [easy to understand]
Chmod command principle and usage details [easy to understand]
绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东
Introduction to nexus and detailed tutorial of Xiaobai using idea to package and upload to nexus3 private server
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
VMware install win10 image
寒门再出贵子:江西穷县考出了省状元,做对了什么?
Believe in yourself and finish the JVM interview this time
2、 Expansion of mock platform
Un an à dix ans
什么是敏捷开发流程
Baobab's gem IPO was terminated: Tang Guangyu once planned to raise 1.8 billion to control 47% of the equity
畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
The computer comes with software to make the background color of the picture transparent (matting white background)
Ocio V2 reverse LUT
如何与博格华纳BorgWarner通过EDI传输业务数据?
一文看懂:数据指标体系的4大类型
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
871. Minimum refueling times