First enable the MySQL slow query log in the MySQL configuration file my.cnf
CentOS/RHEL Based
[cc lang=”bash”]vi /etc/my.cnf[/cc]
Debian/Ubuntu Based
[cc lang=”bash”]vi /etc/mysql/my.cnf[/cc]
Add the records below at the end of the [mysqld] section:
[cc lang=”bash”]slow_query_log = 1
log-slow-queries = /var/log/mysql-slow.log
long_query_time = 1[/cc]
Create slow log file
[cc lang=”bash”]# touch /var/log/mysql-slow.log
# chown mysql:mysql /var/log/mysql-slow.log[/cc]
Restart MySQL service
CentOS/RHEL
[cc lang=”bash”]service mysqld restart[/cc]
Debian/Ubuntu
[cc lang=”bash”]service mysql restart[/cc]
If MariaDB installed
[cc lang=”bash”]service mariadb restart[/cc]
Tail the slow log file
[cc lang=”bash”]tail -f /var/log/mysql-slow.log[/cc]