Database slow query is a normalized case in operation situation. For example, if a new feature in production has a long data loading time, we can check this situation in the application log or database slow query.
Here, is how to set MySql slow query log.
First, open my.cnf
and setting following parameters:
- slow_query_log: boolean, 1 means open slow query log
- slow_query_log_file: slow log saving path
- long_query_time: slow log time threshold, if query time over the threshold will be recorded.
slow_query_log = 1
slow_query_log_file = /var/log/mysql-slow.log
long_query_time = 5
Secondary, restart MySql, and the slow log will work.