One of the built-in tools in MySQL that you can use in optimizing your database is the “slow-query-logging” feature. This feature allows you to log slow running queries to a log file. By default, this feature is not enabled on your VPS and you will need to add a couple of lines in your “/etc/my.cnf” file (in the [mysqld] section) which I have stated below:
log-slow-queries = /var/log/mysql-slow.log
long_query_time = 5
The statements above will log queries taking longer than five second to the specified log file (/var/log/mysql-slow.log). Once finished editing your my.cnf file, restart MySQL by executing the command below:
service mysqld restart