خرید بک لینک

Vote count: 0

The following questions will be answered.

  1. How to enable slow query log in MySQL
  2. How to set slow query time
  3. How to read the logs generated by MySQL

Log analysis is becoming a menace day-by-day. Most tech companies have started using ELK stack or similar tools for Log analysis. But what if you don't have hours to spend on the set up of ELK and just want to spend some time on analysing the logs by your on (manually, that is).

Although, it is not the best way but don't underestimate the power of analysing the logs from the terminal. From the terminal too, we can efficiently analyse the logs but there are limitations to what we can or caot do. I am posting about the basic process of analysing a MySQL log.

asked 1 min ago

1 Answer

Vote count: 0

show variables like '%slow%';

+---------------------------+-----------------------------------+
| Variable_name             | Value                             |
+---------------------------+-----------------------------------+
| log_slow_admin_statements | OFF                               |
| log_slow_slave_statements | OFF                               |
| slow_launch_time          | 2                                 |
| slow_query_log            | OFF                               |
| slow_query_log_file       | /var/lib/mysql/server-slow.log    |
+---------------------------+-----------------------------------+

And then,

show variables like '%long_query%';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 5.000000 |
+-----------------+----------+

Change the long query time to whatever you want. Queries taking more than this will be captured in the slow query log.

set global long_query_time = 2.00;

Now, switch on the slow query log.

set global slow_query_log = 'ON';

flush logs;

Go to the terminal and check the directory where the log file is supposed to be.

cd /var/lib/mysql/

la -lah | grep slow

-rw-rw----  1 mysql mysql 4.6M Apr 24 08:32 server-slow.log

Opening the file - use one of the following commands

cat server-slow.log
tac server-slow.log
less server-slow.log
more server-slow.log
tail -f server-slow.log

How many unique slow queries have been logged during a day?

grep 'Time: 160411.*' server-slow.log | cut -c2-18 | uniq -c

answered 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 5 ارديبهشت 1395 ساعت: 13:58

صفحه بندی