Skip to content

RootDBA

DBA expertise: PostgreSQL, SQL Server & MySQL

Menu
  • Home
  • blog
  • PostgreSql
  • MySql
  • Sql Server
  • About AHMED – Root DBA
Menu

MONITOR MYSQL

Posted on September 2, 2025 by AHMED

Getting MySQL Report from pt-mysql-summary

This tool will generate report what is configuration for MySQL instance , how many replica MySQL has

Or if the MySQL itself is replica , how many uses are connected

What are the users doing

How many databases

How bug us innodb buffer pool size

What is the version of OS and so on

to run te command use the below syntax

pt-mysql-summary  --user=[username] --ask-pass

pt-mysql-summary  --user=root --ask-pass

227491ecbeecd1935a27c44b291a49d6.png

first output will show if this master slave and if it slave and what is the slave server-id
also will show hostname

  • mysql port
  • datadir
  • replication status
  • how many databases there
  • how many prosses connected
    730054ffa037afab00af25e0cd053492.png

1653b3b35407d308899a9d8a9e110064.png

if go down you will find list of prosseslist and what they are doing

836ecb704e7fc676c7d383fafd41f114.png

scroll down you will find mysql variable that are runinng

476823076ff92af4271d6dca1304e6bc.png

scroll down you will find key percona server features that are enabled

363ee3e0f937faaaafcfb0d89751f353.png

scroll down you will find information about innodb that include

  • innodb pool size
  • innodb pool usage
  • percentage of dirty pages
    26a1560dd9fc9a26b79706d568eff94b.png

scroll down you will find information about binary log

configuration file and its path

d3b6135e94c1760d8fbc35b827dce668.png

eaeb453ccd1eccf18ee6e5aef199ada7.png

pt-summary

Pt-summary give system report mainly about the system articture itself
That include

  • Version of os
  • How many cpu
  • How mush memory the system has
  • What are the disk what are the filesystem
  • where each filesystem is mounted
  • networking information
    syntax
pt-summary

4e73af6c6dac3f00cd56cb5952d7ba81.png

MySQL Slow Query Log

What if you runinng issue that querys are runinng slow on your database

Some queries taking maybe five seconds then seconds

There is way to find this slow running query in MySQL
MySQL Slow Query Log log any query that MySQL consider to be slow

  • slow query log consist of all sql statement that take more that variable value long_query_time to execute
  • MySQL engine has define variable called long_query_time by default it measure in seconds
  • any query exceed the threshold in variable long_query_time will be logged and considered as slow query
  • mysqldumpslow is tool installed by default that process slow query log , if you run the utility and location of slow query log it read all slow query log and give you nice summary
  • pt-query-digest also tool that work similar to mysqldumpslow

Enable MySQL Slow Query Log

  • The variable slow-query-log is disabled by default
  • the default value variable long_query_time = is 10 second
  • slow-query-log-file is variable that you defined where to store slow query log
  • The variable log-queries-not-using-indexes that will log query that are not using index (optional)
  • To check if slow query log is enable show global variables like '%slow%';

Note: SElinux must be disabled

d1302b8efc3db425ef136351c04755f3.png

Setup File for Slow Query Log

mkdir -p /var/log/mysql/slow-logs
touch /var/log/mysql/slow-logs/slow-logs.log
chown -R mysql:mysql /var/log/mysql/

f87838ee94437e1400587207176e3d81.png

Enable Slow Query Log

Open my.Cnf file and add the variables
slow-query-log

And slow-query-log-file=path

vi /etc/my.cnf

slow-query-log=true
log-queries-not-using-indexes
log-slow-admin-statements
log-slow-extra
log-slow-replica-statements (Only Replica)
slow-query-log-file = /var/log/mysql/slow-logs/slow-logs.log
long-query-time = 1

798ba7b3b3eeed070d76d4624d0f2985.png

Validate config for any syntax error

mysqld --validate-config

e035284abbf51aa8adfcef69804b42f2.png
restart MySQL
systemctl restart mysqld
f41111661fcf7a904d065acb6cdbe178.png
confirm query log is on

show global variables like '%slow%';

fdf5b0a726596d88927ecbe7b9911778.png

Using Mysqlumpslow and Percona-Digist to Read Slow Query

mysqldumpslow utility

to view slow query we will use mysqldumpslow
syntax

mysqldumpslow [slow query path]

mysqldumpslow /var/log/mysql/slow-logs/slow-logs.log

Note: Only work oracle or community MySQL
Doesn’t support percona mysql
2a9ed21ded3a16be4a2cf6fc78f732f9.png

pt-query-digest

Similar to mysqldumpslow will give summary reading from slow query log

pt-query-digest /var/log/mysql/slow-logs/slow-logs.log

56289d12b35117afb8ca3c39d2db63bf.png
The first in top will show overall status of the query with following

  • Rows examined
  • Query size
  • Total number of query examined
  • Lock time
    338bad312cd6a10b2f0cc9c6987779c8.png
    Also the overview will show rank tabele of the query m how mush total time it took toexecute , what type of dml done on query and on which database
    7b77e9c1abc8c85eae47a0d24338a9a7.png
    Scroll down it will display query with higtiest time to execute to be on top ascending to lowest
    First you want to see is query time distribution

It start from most expensive that if this query ten seconds plus this display

b6010eb300383f56e45b792644e33d94.png

Below will show the query itself who execute it , when it was executed , by which user it executed

33fcb674b99b4f76119932ae347beec2.png

0
Visited 16 times, 1 visit(s) today
Category: mysql

Post navigation

← mysql replication troublshooting
enable and configuring auditing and masking in mysql →
© 2025 RootDBA | Powered by Minimalist Blog WordPress Theme