/go/querytop reads MariaDB's general query log, /var/log/mysql.log, and prints the ten SELECT statements that appear most often. If the log is missing, nearly empty, or hasn't been written to in the last hour, the command assumes query logging is off and turns it on by running my –log. That step regenerates /etc/my.cnf and restarts MariaDB. It then asks you to try again after five minutes. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.
Quick start
# Show the most frequently executed SELECT queries
/go/querytop
On the first run, it starts logging and exits. Run it again after about five minutes.
Examples
# First run: starts logging and exits
/go/querytop
# Run again after a few minutes
/go/querytop
# Check that the general query log is on
mariadb -e "SHOW VARIABLES LIKE 'general_log%';"
# Check the size of the log
ls -lh /var/log/mysql.log
# Turn logging off again (regenerates the configuration and restarts MariaDB)
/go/my
Output
When the log is active:
MOST FREQUENTLY EXECUTED SQL QUERIES:
-------------------------------------
1432 SELECT option_value FROM wp_options WHERE option_name = 'siteurl' LIMIT 1
876 SELECT COUNT(*) FROM wp_posts
...
Each line is the number of times that exact text appears, followed by the query text from SELECT to the end of the line.
When logging has to be started:
Start MariaDB logging...
Try again after 5 minutes.
| Outcome | What you get |
|---|---|
| Log is active | The ranking, exit status 0. |
| Logging was started | The two messages above (plus any output from my), exit status 1. |
The exit status 1 after starting logging means "try again later". It is not an error.
See the full reference at /go/querytop and the GoAdmio command index.
GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.
