


Anemometer graphically displays MySQL slow log tool construction and usage example analysis
Introduction: Anemometer is a tool for graphically displaying MySQL slow logs. Combined with pt-query-digest, Anemometer can easily help you analyze slow query logs, allowing you to easily find which SQL needs to be optimized
This is the Box Anemometer, the MySQL Slow Query Monitor. This tool is used to analyze slow query logs collected from MySQL instances to identify problematic queries
Related learning recommendations:PHP programming from entry to proficiency
Environment Overview
Take the latest version of percona-toolkit 3.0.10 at the time of writing this article as an example
The corresponding version of the mysql database is 5.7.21, and the binary installation
http and php are both built-in versions of the system CentOS Linux release 7.4.1708 (Core)
The steps that need to be installed are as follows:
1.Percona-toolkit tool installation
2.php web environment construction and installation
3.Anemometer and configuration
4.Import slow query log
5. Visit the interface and view slow queries
6. Other related and problem solving
0. Overall architecture
1. Installation of percona-toolkit
Installation purpose: pt-query-digest is percona -A tool in toolkit, its function is to analyze slow query logs, collect statistics on MySQL slow query logs and display them in a friendly manner
Download address: https://www.percona.com/downloads/ percona-toolkit/
Installation method (rpm):
1. Download the package, wget https://www.percona.com/ downloads/percona-toolkit/3.0.10/binary/redhat/7/x86_64/percona-toolkit-3.0.10-1.el7.x86_64.rpm
2. Install dependencies, yum install perl-DBI perl-DBD-MySQL perl-IO-Socket-SSL perl-Digest-MD5 -y
3. Formal installation, rpm -ivh percona-toolkit-3.0. 10-1.el7.x86_64.rpm
4. Verification of installation completion, pt-query-digest --version pt-query-digest 3.0.10
Installation method (tar binary)
1. Download the package, wget https://www.percona.com/downloads/percona-toolkit /3.0.10/binary/tarball/percona-toolkit-3.0.10_x86_64.tar.gz
2. Install dependencies, yum install perl-DBI perl-DBD-MySQL perl-IO-Socket-SSL perl-Digest-MD5 -y<br>
3. Unzip the package, tar xf percona-toolkit-3.0.10_x86_64.tar.gz
4. Use the tool directly, ./percona-toolkit-3.0.10/bin/pt-query-digest --version<br>pt-query-digest 3.0.10
2. Construction of php web environment
Installation purpose: Anemometer needs to depend on
LAMP environment Installation of LAMP environment:
1. Install apache, yum install httpd httpd-devel -y
2. Install php, yum install php php-mysql php-common php-bcmath php-dba php-cli php-gd php-mbstring php-mcrypt php-devel php-xml php-pdo -y<br>
3. Modify the time zone, vim /etc/php.ini
, change it to date.timezone = PRC
Startup of LAMP environment:
1. Start, systemctl start httpd
2. Shutdown, systemctl stop httpd
3. Restart, systemctl restart httpd
4. View, systemctl status httpd
##3. Install Anemometer and Configuration
1. Download and install:Installation purpose: install Anemometer application
Download address:
https://github.com/box/Anemometer
Download package:
git clone https://github.com/box/Anemometer.gitMove to the corresponding path:
mv Anemometer /var/www/html/anemometer2. The corresponding permissions of the Anemometer host need to be granted on the target slow query database.
1. Purpose, used to analyze the target slow query database explain execution plan.
2. Authorization,
grant select on *. * to 'anemometer'@'$ip' identified by '123456';flush privileges; ($ip is the IP address corresponding to the Anemometer host)
3. Modify the configuration file and add explain to read the user password information
cp conf/sample.config.inc.php conf/config.inc.php vim conf/config.inc.php\\
##4. Modify the configuration file Point to the data source file, vim conf/datasource_localhost.inc.php, of course you can also directly vim conf/config.inc.php
5、初始化数据源的数据库表的配置,mysql -uroot -p123456 -h127.0.0.1 -P5700 < install.sql,每个datasource源头可以对应不同的数据库database(修改install.sql的内容)
4. 导入慢查询日志
1、慢查询主机推送格式
d2b98b1340f0b4f83352c1411db32fe75. 访问界面,查看慢查询
http://$ip/anemometer/ ($ip为Anemometer主机对应ip地址)
6、其他相关和问题解决
1、对于anemometer的主机上,需要进行慢查询主机hostname和ip的映射(修改/etc/hosts进行配置),目的在于慢查询explain执行计划的目标主机解析
#collect mysql slowquery log into lepus database步骤中,$HOSTNAME:$mysql_port
数据库存取的格式,hostname_max类似这种,cnwangdawei:5700
2、中文乱码的问题,在#collect mysql slowquery log into lepus database步骤中添加 --charset=utf8
3、慢查询主机数据库是5.7版本的数据库,可能出现界面ts_cnt不显示,替换percona toolkit为新版本,2.x.x -----> 3.x.x
4、表结构和状态字符集显示乱码,添加mysqli的字符集设定,vim /var/www/html/anemometer/lib/QueryExplain.php
新增(194行后增加),$this->mysqli->query("set names utf8");
The above is the detailed content of Anemometer graphically displays MySQL slow log tool construction and usage example analysis. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
