学习笔记:Analyze MySQL Performance及慢日志的开启
Table of Contents
Brought to you by Rick James
Analyze MySQL Performance
When asked to analyze the performance of a MySQL server, there are two main tasks (tuning and slowlog) I like to start with. The groundwork for them can be done by the customer.
当被要求分析MySQL服务器的性能时,我想从两个主要任务(调优和慢速日志)开始。他们的基础工作可以由客户完成。
The deliverables: 可交付成果:
⚈ Short list of settings (VARIABLES) to change in my.cnf.
⚈ Recommendations for speeding up the 'worst' queries.
⚈ (possibly) Schema or Architectural recommendations.
⚈在my.cnf中更改的设置(VARIABLES)的简短列表。
⚈加速“最差”查询的建议。
⚈(可能)schema或架构建议。
In doing these tasks, I get a feel for what the system is doing, thereby jumpstarting any further involvement with the customer's site.
The tuning is usually a one-time task, but may be rerun as the data grows and/or major changes are made to the application.
The Slowlog analysis should be rerun periodically.
在完成这些任务时,我了解系统正在做什么,从而开始进一步参与客户的网站。
调整通常是一次性任务,但随着数据的增长和/或对应用程序进行重大更改,可能会重新运行。
应定期重新运行Slowlog分析。
Tuning
Please provide
⚈ How much RAM in the server
⚈ SHOW VARIABLES; -- the tunables
⚈ SHOW GLOBAL STATUS; -- various metrics
Please take GLOBAL STATUS after the server has been running at least 24 hours. (Otherwise things like 'cold cache' invalidate some of the findings.)
The SHOWs need to be in machine readable format.
Privacy: There is nothing very sensitive in the SHOWs. However, if you are especially paranoid, you could mask out any ip addresses and host names. Nothing significant will be lost from the analysis.
With those, I will use an automated script compute about 200 formulas and check for reasonable values. Usually about 20 are flagged as 'suspect'. Then I review them the results and clean up things. The bottom line is a few concrete recommendations for
⚈ Changing a few variables.
⚈ (maybe) Converting away from MyISAM. (I have tips on the task, if you have not yet done such.)
⚈ (maybe) Turn off the Query cache. (Perhaps under 5% of Production systems benefit from the QC.)
⚈ (probably) Turning on and analyzing the slowlog (below).
If you choose to post online, see a free tool such as
⚈ post.it
⚈ pastebin
Caveat: pastebin may get this (for reasons unknown): "This page is no longer available. It has either expired, been removed by its creator, or removed by one of the Pastebin staff."
Slow queries and Slowlog
Setup:
⚈ Set long_query_time = 1 -- Preferrable in my.cnf We may change that threshhold up or down later, but this is a reasonable start.
⚈ Set up the slowlog to be captured to FILE.
⚈ Turn on (the details of this vary with the Version)
⚈ Wait at least 24 hours.
Writing slow_log to file -- this is preferred, since there are tools for condensing such:
log_output = FILE
slow_query_log = ON
slow_query_log_file = (fullpath to some file)
long_query_time = 1
log_slow_admin_statements = ON
log_queries_not_using_indexes = OFF
Notes:
⚈ log_output can be TABLE to write to mysql.slow_log, or FILE,TABLE to write both
⚈ slow_query_log_file has a default; is not needed for TABLE
⚈ long_query_time is a float, and can be as low as 0, but that gets verbose; default is a 'useless' 10
⚈ admin statements tend to be slow but infrequent
⚈ not_using_indexes is mostly clutter; simply worry about those that are slow
⚈ If running on a Slave, consider using log_slow_slave_statements
Other options (version dependent; incomplete): 其他选项(依赖于版本;不完整)
log_slow_rate_limit=100
log_slow_rate_type=query
log_slow_verbosity=full
slow_query_log_always_write_time=1
slow_query_log_use_global_control=all
innodb_monitor_enable=all
userstat=1
Gather results for me (preferrably using FILE):
⚈ Digest the results using either of these:
`pt-query-digest` -- from Percona.com
`mysqldumpslow -s t`
⚈ Grab the first few (perhaps 5) queries. They will be sorted by (frequency * avg-time), which is the most useful.
⚈ Provide SHOW CREATE TABLE -- for each table
⚈ Provide EXPLAIN SELECT ... -- for each query
Analyze Results: Usually (not always), I can then provide a concrete suggestion on speeding up each query:
分析结果:通常(并非总是),我可以提供加速每个查询的具体建议:
⚈ Add a particular index (often 'composite')
⚈ Reformulate the query (a simple case is not hiding an indexed column in a function; more complex involves adding/removing subqueries)
⚈ Recommend schema change
⚈ Possibly even a architectural change (EAV is a common problem)
⚈添加特定索引(经常'复合')
⚈重新构造查询(一个简单的例子不是隐藏函数中的索引列;更复杂的涉及添加/删除子查询)
⚈推荐架构更改
⚈可能甚至是架构更改(EAV是常见问题)
Some common recommendations:
Many-to-Many mapping schema
Speeding up wp_postmeta
explode-implode problem of JOIN + GROUP BY
Pagination via OFFSET - instead "remember where you left off"
Posted June, 2017; Slowlog: Sep, 2017
学习笔记:Analyze MySQL Performance及慢日志的开启的更多相关文章
- 学习笔记:MySQL Big DELETEs 删除大量数据
原文地址:http://mysql.rjweb.org/doc.php/deletebig Table of Contents The ProblemWhy it is a ProblemInnoDB ...
- (1.3)学习笔记之mysql体系结构(C/S整体架构、内存结构、物理存储结构、逻辑结构)
目录 1.学习笔记之mysql体系结构(C/S架构) 2.mysql整体架构 3.存储引擎 4.sql语句处理--SQL层(内存层) 5.服务器内存结构 6.mysql如何使用磁盘空间 7.mysql ...
- SQLMAP学习笔记2 Mysql数据库注入
SQLMAP学习笔记2 Mysql数据库注入 注入流程 (如果网站需要登录,就要用到cookie信息,通过F12开发者工具获取cookie信息) sqlmap -u "URL" - ...
- ref:学习笔记 UpdateXml() MYSQL显错注入
ref:https://www.cnblogs.com/MiWhite/p/6228491.html 学习笔记 UpdateXml() MYSQL显错注入 在学习之前,需要先了解 UpdateXml( ...
- (1.1)学习笔记之mysql体系结构(内存、进程、线程)
关键词:mysql体系结构 参考:https://www.cnblogs.com/zhoubaojian/articles/7866292.html 一.mysql体系架构概述 1.mysql体系结构 ...
- Linux学习笔记07—mysql的配置
一.mysql简介 说到数据库,我们大多想到的是关系型数据库,比如mysql.oracle.sqlserver等等,这些数据库软件在windows上安装都非常的方便,在Linux上如果要安装数据库,咱 ...
- 性能优化之mysql优化——慢查日志的开启方式和存储
-- MySQL优化 -- mysql 慢查日志的开启方式和存储 -- 1) 查看mysql是否开启慢查询日志 SHOW VARIABLES LIKE 'slow_query_log'; -- 2) ...
- 《MySQL实战45讲》学习笔记2——MySQL的日志系统
一.日志类型 逻辑日志:存储了逻辑SQL修改语句 物理日志:存储了数据被修改的值 二.binlog 1.定义 binlog 是 MySQL 的逻辑日志,也叫二进制日志.归档日志,由 MySQL Ser ...
- 学习笔记之MySQL的使用
什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库. 每个数据库都有一个或多个不同的 API 用于创建,访问,管理,搜索和复制所保存的数据. 我们也可以将数据存储在文 ...
随机推荐
- logstash-input-jdbc同时同步多个表
同步一个表,可以参考我的上一篇 logstash-jdbc-input与mysql数据库同步 同步多个表的做法,跟一个表类似,唯一不同的是 .conf 文件中的配置 在这里我加了一个脚本文件jdbc- ...
- GNU的编译器
GNU的编译器可以编译C或C++语言, 编译C语言使用gcc,编译C++语言使用g++ 如果是使用Linux或者Unix系统(Mac)可以使用以下命令: gcc -v 或者 g++ -v 来查看是否安 ...
- Spring Boot项目的内嵌容器
一.关于容器 刚才开始使用spring boot的开发者会有种很直观的感觉,servlet容器“不见了”.之前开发web项目,都是把程序写完后部署到servlet容器(比如Tomcat),但是使用sp ...
- WebLogic 12c Linux 命令行 安装
最近负责在Linux上安装WebLogic Server 12c,客户说要安装最新的版本,版本号为 12.1.X(12.1.2,12.1.3).开始以为和旧版安装一样,使用控制台的方式,下载bin文件 ...
- 外网配置花生壳动态域名解析实现外网访问本地iis及vs实时调试
描述:假如已连外网,具备一台路由器的情况下在路由器设置页面配置花生壳动态域名解析,使得外网可以访问到本地iis 托管的web服务,模拟真实环境调试应用程序. 网络运营商ip的动态分配,通常网络提供商给 ...
- 【转载】H5页面列表的无线滚动加载(前端分页)
本代码基于Vue的架构 1.首先,要滚动的内容放在一个‘id=box’ 的div里,对div进行scroll事件的监听 <div id="box" class="m ...
- IIS日志自动清理
IIS在运行的过程中日志会不停地增长,若iis的网站被频繁的调用或不当的调用,则会产生很多日志.我在系统运维的时候曾出现过20G的系统盘,由于合作商开发的程序有问题,每几百微秒调用一次web服务,短期 ...
- C#基础知识回顾:2.使用DbProviderFactory实现多数据库访问
ADO.Net 2.0中,在System.Data.Common中引入了一系列抽象基类,使得开发人员能够在不依赖具体数据库操作的情况下进行编写数据访问代码,它们分别是DbConnection.DbCo ...
- 解决:oracle+myBatis ResultMap 类型为 map 时,表字段类型有 Long/Blob/Clob 时报错
前言:最近在做一个通用查询单表的组件,所以 sql 的写法就是 select *,然后 resultType="map" .如果数据库中的表里有字段类型为 Long 等类型时,my ...
- 设计模式(11)--Flyweight(享元模式)--结构型
作者QQ:1095737364 QQ群:123300273 欢迎加入! 1.模式定义: 享元模式是对象的结构模式.享元模式以共享的方式高效地支持大量的细粒度对象. 2.模式特点: 享元模 ...