FeaturesWP CloudPricingEE CLIContactMy Account
Features
Team Access & User Permissions
Install
Resources
Community
CLEAR
Tutorials
Mysql
Analyse slow-query-log using mysqldumpslow & pt-query-digest
Topics
On this page
-
- Getting Started
- Git and File-System Layout (non-default setup)
- Version Constraints
- Managing Themes and Plugins (for entire WordPress site)
- Updating Themes and Plugins (for entire WordPress site)
- Adding Composer Support to Your Own Themes and Plugins (for developers)
- Using Composer to Manage Own Theme/Plugin Dependencies (for developers)
-
- Assigning Multiple IP Addresses to Single LAN Card
- Disable IPv6 on Ubuntu 12.04
- dsh – distributed shell
- fdupes – find & replace duplicate files with hardlinks
- GPG Keys Cheatsheet
- Increase "Open Files Limit"
- kill all php, nginx, mysql or any kind of processes
- Passwordless Authentication for SSH
- Screen
- search replace in multiple files useing grep xargs sed
- Setup sftp
- sysctl.conf
- Timezone Sync
- Using Google Public DNS on Ubuntu Server
- Using openssl to match private key, cerificate and CSR
- Configure Postfix to Use Gmail SMTP on Ubuntu
- Logrotate Example for Custom Logs
- PHP 5.5, MySQL, Postfix, Nginx and WordPress on Ubuntu
- Serverdensity
- Upgrade Ubuntu 10.04 to 12.04
- Using find and sed to replace strings in multiple files
- Webmin
-
- .my.cnf – mysql user & password
- Analyse slow-query-log using Anemometer
- Improving MySQL Query Cache
- MySQL Query Profiling
- Reset MySQL root password
- tuning-primer.sh – an alternative for mysqltuner
- Using MariaDB 10
- Install/Upgrade to MySQL 5.6 on Ubuntu 12.04 LTS
- Change WordPress Domain Name
- Character Sets and Collations
- Enable innodb_file_per_table
- Enable Remote Access (Grant)
- Installing Percona Toolkit
- Using tmpfs for temporary folder creation
- YARPP and InnoDB
- Convert MyISAM to InnoDB
- Using tmpfs for mysqldump & mysqlimport
- Convert from INNODB to MYISAM
- Analyse slow-query-log using mysqldumpslow & pt-query-digest
- mysqlcheck with cron to optimize automatically
- Using MySQLTuner to Optimize MySQL configuration
-
-
- Directly connect to PHP-FPM
- Generating core-dump for php5-fpm
- GeoIP
- Having php5 and php7 on same system.
- Install Xdebug and configure it with webgrind
- Installation of PHP Code Review Tools
- memcache
- PHP's Zend Opcache Config & Web Viewer
- Setting Sqlite support with PHP
- Using HHVM with PHP-FPM Fallback
- Using Redis for PHP Sessions on Ubuntu Server
- Installing PhpMyAdmin Quickly
- Moving PHP's session storage to tmpfs
- Install Xdebug and configure it with Netbeans
- Nginx – Enable PHP-FPM Status Page
- PHP-FPM: Socket vs TCP/IP and sysctl tweaking
- APC Cache Optimization & Monitoring Using Web Interface
- Checking if PHP/WordPress can send mails
- Debugging PHP Scripts Using slow_log and more
- Increase file upload size limit in PHP-Nginx
- Increase PHP script execution time with Nginx
-
- Performance Optimization
- Remove Query string of css/js files
- Setup ElasticSearch with ElasticPress
- Using Redis for WordPress Object-Cache
- WooCommerce Window Shopping Caching Technique
- Moving WordPress To New Server (Faster)
- Better wp-cron using linux's crontab
- 404 error- Page not Found!!!
- Debugging WordPress with Nginx
Enable slow-query-log
mysqldumpslow
pt-query-digest
mysqlsla
Analyse slow-query-log using mysqldumpslow & pt-query-digest
Note: This is written for mysql version 5.5. Old mysql version has slightly different syntax.
Mysql can log slow queries which takes longer to execute. In some cases this is expected but some queries take longer because of coding mistakes. slow-query-log can definitely help you find those queries and make it easy to debug your application.
In WordPress world, many plugins are often coded my amateurs who have no idea about the scale at which big sites operate! Its better to use slow-query-log to find out such plugins.
Enable slow-query-log
You can enable slow-log by un-commenting following lines in /etc/mysql/my.cnf. If you’re using EE4, the location of mysql config file is mentioned in it’s documentation.
slow-query-log = 1
slow-query-log-file = /var/log/mysql/mysql-slow.log
long_query_time = 1
log-queries-not-using-indexes = 1
Last line will tell slow-log to log queries not using indexes. You can keep it commented if you want to ignore queries which are not using indexes.
If your server has less RAM and you are seeing many of your queries in slow-query-log, you may increase value of long_query_time.
Its advisable to enable slow-query-log while debugging only and disable it once you are done with it. Lets move on to analysis part.
mysqldumpslow
This comes bundled with mysql-server.
mysqldumpslow /var/log/mysql/mysql-slow.log
Following will show top 5 query which returned maximum rows. It can find queries where you missed LIMIT clause. A common performance killer!
mysqldumpslow -a -s r -t 5 /var/log/mysql/mysql-slow.log
Following will sort output by count i.e. number of times query found in slow-log. Most frequency queries sometimes turned out to be unexpected queries!
mysqldumpslow -a -s c -t 5 /var/log/mysql/mysql-slow.log
pt-query-digest
This is part of percona toolkit.
Then basic usage is:
pt-query-digest /var/log/mysql/mysql-slow.log
If you have multiple databases, you can enable filtering for a particular database:
pt-query-digest /var/log/mysql/mysql-slow.log --filter '$event->{db} eq "db_wordpress"'
mysqlsla
This is another 3rd party tool. Can be downloaded from here.
Basic Usage:
./mysqlsla /var/log/mysql/mysql-slow.log
Filter for a database:
./mysqlsla /var/log/mysql/mysql-slow.log -mf "db=db_name"
https://github.com/box/Anemometer
Don’t forget..
Always restart mysql, every time you enable/disable slow-query-log for changes to take effect.
Convert from INNODB to MYISAM
PREVIOUS
mysqlcheck with cron to optimize automatically
NEXT
Comments
-
Thanks for good article.
But before it must do this:
mkdir /var/log/mysql/
touch /var/log/mysql/mysql-slow.log
chown -R mysql:mysql /var/log/mysql/
And restart mysql:
service mysql restart-
I will check again. I guess
/var/log/mysqlgets created with mysql installation.Thanks for your comment and commands though. Might help somebody. 🙂
-
Features
- Server Setup & Management
- Site Creation & Management
- Create WP Cloud Sites
- Speed & Caching
- Firewall Protection
- Backups & Recovery
- Logs & Monitoring
- Deployments & Developer Tools
- Team Access & User Permissions
Useful Links
Product
Other Products
Subscribe for curated product updates, tips, and announcements.
"*" indicates required fields
Phone
This field is for validation purposes and should be left unchanged.
Email*
SIGN ME UP
Δ
© rtCamp, since 2009. All rights reserved.
