Slow query open and query

  • Enable slow query temporarilyset global slow_query_log=1 The default timeout is 10 seconds.
  • Permanently turn on slow query inmy.cnfIn the file[mysqld]Set in theslow_query_log=1And set upslow_query_log_file=xxxx
  • Set the slow query thresholdset global long_query_time=5Set the slow query threshold for 5s. The delay takes effect after you log in again.
  • Select * from SQL where threshold is exceeded:show global status like '%slow_queries%', you can also view the log file through slow query.

Tool mysqldumpslow

  • You can usemysqldumpslowTool to view slow query SQL statements,mysqldumpslow - s: sorting,r: the reverse,l: Lock time,g: Indicates the regular matching mode.
    • Such as:mysqldumpslow -s r -t 3 /var/lib/mysql/localhost-slow.log: Gets the three SQL statements that return the most records
    • mysqldumpslow -s c -t 3 /var/lib/mysql/localhost-slow.log: Obtains the three SQL statements that are accessed the most times