Страница 1 из 1

Временное ведение лога всех запросов к MySQL

Добавлено: 2009-07-05 10:45:23
100matolog
Задача - Нужно проанализировать запросы только в текущий момент без ребута мускуля.

На опеннете предложили через tcpdump - но это , имхо, изврат..

Знаю есть опция mysql> set global general_log = on; которая позволяет сливать в лог историю запросов - но в версии 5.1.22 стоит ограничение на длину запроса в логе ..В поздней версии это пофиксили . Но пересобирать мускуль очень не хочется..

ЗЫ uname -a
FreeBSD 6.3-RELEASE FreeBSD 6.3-RELEASE #0

Re: * Редактировать сообщение * Пожаловаться на это со

Добавлено: 2009-07-05 11:11:27
zg
100matolog писал(а):Господа - кто как делает сабж?
чего? :cz2:
100matolog писал(а):На опеннете предложили через tcpdump - но это , имхо, изврат..
:crazy:
100matolog писал(а):Знаю есть опция mysql> set global general_log = on; - но в версии 5.1.22 стоит ограничение на длину лога..В поздней версии это пофиксили . Но пересобирать мускуль очень не хочется..
:bn:

можно ещё раз тоже самое, только полным текстом? :smile:

Re: Временное ведение лога всех запросов к MySQL

Добавлено: 2009-07-05 11:15:32
100matolog
что-то где-то глюкнуло

Re: Временное ведение лога всех запросов к MySQL

Добавлено: 2009-07-05 11:41:12
zg
100matolog писал(а):Задача - Нужно проанализировать запросы только в текущий момент без ребута мускуля.
тут есть трудности

Код: Выделить всё

zg# mysql -e 'select @@log;'
+-------+
| @@log |
+-------+
|     0 |
+-------+
zg# mysql -e 'set @@log="/var/db/mysql/query.log";'
ERROR 1238 (HY000) at line 1: Variable 'log' is a read only variable
zg#
только так

Код: Выделить всё

zg# grep mysql /etc/rc.conf
mysql_enable="YES"
mysql_args="--log=/var/db/mysql/query.log"
zg# pwd
/var/db/mysql
zg# ls -lah
total 20544
drwx------   4 mysql  mysql   512B  5 июл 13:36 .
drwxr-xr-x  11 root   wheel   512B  5 июл 00:00 ..
-rw-rw----   1 mysql  mysql   5,0M  5 июл 13:36 ib_logfile0
-rw-rw----   1 mysql  mysql   5,0M  4 июл 15:10 ib_logfile1
-rw-rw----   1 mysql  mysql    10M  5 июл 13:36 ibdata1
drwx------   2 mysql  mysql   1,5K  4 июл 15:06 mysql
-rw-rw----   1 mysql  mysql   177B  5 июл 13:36 query.log
drwx------   2 mysql  mysql   512B  4 июл 15:06 test
-rw-rw----   1 mysql  mysql   3,2K  5 июл 13:36 zg.test.local.err
-rw-rw----   1 mysql  mysql     4B  5 июл 13:36 zg.test.local.pid
zg# cat query.log
/usr/local/libexec/mysqld, Version: 5.0.77-log (FreeBSD port: mysql-server-5.0.77_1). started with:
Tcp port: 0  Unix socket: (null)
Time                 Id Command    Argument
zg# mysql -e 'show variables' > /dev/null
zg# cat query.log
/usr/local/libexec/mysqld, Version: 5.0.77-log (FreeBSD port: mysql-server-5.0.77_1). started with:
Tcp port: 0  Unix socket: (null)
Time                 Id Command    Argument
090705 13:36:40       1 Connect     root@localhost on
                      1 Query       select @@version_comment limit 1
                      1 Query       show variables
                      1 Quit
zg#
рестарт занимает от 5 до 10-30 секунд

Re: Временное ведение лога всех запросов к MySQL

Добавлено: 2009-07-05 12:14:15
zg
http://dev.mysql.com/doc/refman/5.1-mar ... eneral_log

Код: Выделить всё

Version Introduced	5.1.12
Command Line Format	--general-log
Config File Format	general-log
Option Sets Variable	Yes, general_log 
Variable Name	general_log
Variable Scope	Global
Dynamic Variable	Yes
Value Set 		Type	boolean
Default	OFF

Whether the general query log is enabled. The value can be 0 (or OFF) to disable the log or 1 (or ON) to enable the log. The default value depends on whether the --general_log option is given (--log before MySQL 5.1.29). The destination for log output is controlled by the log_output system variable; if that value is NONE, no log entries are written even if the log is enabled. The general_log variable was added in MySQL 5.1.12.
гм... в 5.1.22 может проканать :smile: но в любом случае надо ещё использовать

Код: Выделить всё

general_log_file Version Introduced	5.1.12
Command Line Format		--general-log-file=file_name	5.1.29

Config File Format		general_log_file	5.1.29

Option Sets Variable	Yes, general_log_file 
Variable Name	general_log_file
Variable Scope	Global
Dynamic Variable	Yes
Value Set 		Type	filename
Default	host_name.log



The name of the general query log file. The default value is host_name.log, but the initial value can be changed with the --general_log_file option (--log before MySQL 5.1.29). This variable was added in MySQL 5.1.12.
попробуй, может пройдёт фокус. Ну а на счёт ограничений... попробуй, вдруг найдёшь то, что ищешь :smile:

В конце концов, есть такая примочка http://dev.mysql.com/doc/refman/5.1-mar ... ow-queries

Код: Выделить всё

--log-slow-queries[=file_name] Command Line Format	--log-slow-queries[=name]
Config File Format	log-slow-queries
Option Sets Variable	Yes, log_slow_queries 
Variable Name	log_slow_queries
Variable Scope	Global
Dynamic Variable	Yes
Value Set 		Type	boolean



This option enables logging to the slow query log, which contains entries for all queries that have taken more than long_query_time seconds to execute. See the descriptions of the --log-long-format and --log-short-format options for details. 

The log output destination can be selected with the --log-output option as of MySQL 5.1.6. Before 5.1.6, logging occurs to the slow query log file. If you omit the file name, MySQL uses host_name-slow.log as the file name. See Section 5.2.1, “Selecting General Query and Slow Query Log Output Destinations”, and Section 5.2.5, “The Slow Query Log”. 

As of MySQL 5.1.29, the --log-slow-queries option is deprecated and will be removed (along with the log_slow_queries system variable) in MySQL 7.0. Instead, use the --slow_query_log option to enable the slow query log and the --slow_query_log_file=file_name option to set the slow query log file name.