56,940
社区成员




MariaDB [mysql]> set log_output = 'table';
ERROR 1229 (HY000): Variable 'log_output' is a GLOBAL variable and should be set with SET GLOBAL
MariaDB [mysql]> set global log_output = 'table';
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select 'a';
+---+
| a |
+---+
| a |
+---+
1 row in set (0.00 sec)
MariaDB [mysql]> set global general_log=on;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select 'a';
+---+
| a |
+---+
| a |
+---+
1 row in set (0.01 sec)
MariaDB [mysql]> set global general_log=off;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> set global log_output='file';
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select * from mysql.general_log;
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
| event_time | user_host | thread_id | server_id | command_type | argument |
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
| 2016-04-25 19:02:15 | root[root] @ localhost [::1] | 3 | 1 | Query | select 'a' |
| 2016-04-25 19:02:24 | root[root] @ localhost [::1] | 3 | 1 | Query | set global general_log=off |
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
2 rows in set (0.00 sec)
MariaDB [mysql]> show columns from mysql.general_log;
+--------------+---------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------------+------+-----+-------------------+-----------------------------+
| event_time | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| user_host | mediumtext | NO | | NULL | |
| thread_id | bigint(21) unsigned | NO | | NULL | |
| server_id | int(10) unsigned | NO | | NULL | |
| command_type | varchar(64) | NO | | NULL | |
| argument | mediumtext | NO | | NULL | |
+--------------+---------------------+------+-----+-------------------+-----------------------------+
6 rows in set (0.00 sec)
MariaDB [mysql]> select * from mysql.general_log where user_host = 'root[root] @ localhost [::1]' and thread_id = 3;
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
| event_time | user_host | thread_id | server_id | command_type | argument |
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
| 2016-04-25 19:02:15 | root[root] @ localhost [::1] | 3 | 1 | Query | select 'a' |
| 2016-04-25 19:02:24 | root[root] @ localhost [::1] | 3 | 1 | Query | set global general_log=off |
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
2 rows in set (0.04 sec)
注意不要在生产环境上用,会有附加的开销。[/quote]
MariaDB [mysql]> set log_output = 'table';
ERROR 1229 (HY000): Variable 'log_output' is a GLOBAL variable and should be set with SET GLOBAL
MariaDB [mysql]> set global log_output = 'table';
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select 'a';
+---+
| a |
+---+
| a |
+---+
1 row in set (0.00 sec)
MariaDB [mysql]> set global general_log=on;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select 'a';
+---+
| a |
+---+
| a |
+---+
1 row in set (0.01 sec)
MariaDB [mysql]> set global general_log=off;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> set global log_output='file';
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select * from mysql.general_log;
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
| event_time | user_host | thread_id | server_id | command_type | argument |
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
| 2016-04-25 19:02:15 | root[root] @ localhost [::1] | 3 | 1 | Query | select 'a' |
| 2016-04-25 19:02:24 | root[root] @ localhost [::1] | 3 | 1 | Query | set global general_log=off |
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
2 rows in set (0.00 sec)
MariaDB [mysql]> show columns from mysql.general_log;
+--------------+---------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------------+------+-----+-------------------+-----------------------------+
| event_time | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| user_host | mediumtext | NO | | NULL | |
| thread_id | bigint(21) unsigned | NO | | NULL | |
| server_id | int(10) unsigned | NO | | NULL | |
| command_type | varchar(64) | NO | | NULL | |
| argument | mediumtext | NO | | NULL | |
+--------------+---------------------+------+-----+-------------------+-----------------------------+
6 rows in set (0.00 sec)
MariaDB [mysql]> select * from mysql.general_log where user_host = 'root[root] @ localhost [::1]' and thread_id = 3;
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
| event_time | user_host | thread_id | server_id | command_type | argument |
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
| 2016-04-25 19:02:15 | root[root] @ localhost [::1] | 3 | 1 | Query | select 'a' |
| 2016-04-25 19:02:24 | root[root] @ localhost [::1] | 3 | 1 | Query | set global general_log=off |
+---------------------+------------------------------+-----------+-----------+--------------+----------------------------+
2 rows in set (0.04 sec)
注意不要在生产环境上用,会有附加的开销。
set global general_log = on;
执行你的程序
set global general_log = off;
相应的sql会记录在 select @@global.general_log_file 指定的文件里