新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
Linux下查看mysql數(shù)據(jù)庫操作記錄具體方法
Linux下如何查看mysql數(shù)據(jù)庫操作記錄?本篇文章重點為大家講解一下Linux下查看mysql數(shù)據(jù)庫操作記錄具體方法,有需要的小伙伴可以參考一下。

創(chuàng)新互聯(lián)建站堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都網站設計、成都網站制作、企業(yè)官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯(lián)網時代的營口網站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
Linux下查看mysql數(shù)據(jù)庫操作記錄具體方法
MySQL中的參數(shù)general_log用來控制開啟、關閉MySQL查詢日志,參數(shù)general_log_file用來控制查詢日志的位置。所以如果你要判斷MySQL數(shù)據(jù)庫是否開啟了查詢日志,可以使用下面命令。general_log為ON表示開啟查詢日志,OFF表示關閉查詢日志。
mysql> show variables like '%general_log%';
+------------------+------------------------------+
| Variable_name | Value |
+------------------+------------------------------+
| general_log | OFF |
| general_log_file | /var/lib/mysql/DB-Server.log |
+------------------+------------------------------+
2 rows in set (0.00 sec)
另外,MySQL的查詢日志支持寫入文件或寫入數(shù)據(jù)表兩種形式,這個由參數(shù)log_output控制,如下所示:
mysql> show variables like 'log_output';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output | FILE |
+---------------+-------+
1 row in set (0.00 sec)
開啟MySQL查詢日志
mysql> set global general_log = on;
Query OK, 0 rows affected (0.11 sec)
mysql> show variables like 'general_log';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| general_log | ON |
+---------------+-------+
1 row in set (0.02 sec)
關閉MySQL查詢日志
mysql> show variables like 'general_log';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| general_log | ON |
+---------------+-------+
1 row in set (0.01 sec)
mysql> set global general_log=off;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like 'general_log';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| general_log | OFF |
+---------------+-------+
1 row in set (0.00 sec)
設置日志輸出方式為表
如果設置log_output=table的話,則日志結果會記錄到名為gengera_log的表中,這表的默認引擎是CSV)。
mysql> show variables like 'log_output';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output | FILE |
+---------------+-------+
1 row in set (0.00 sec)
mysql> set global log_output='table';
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'log_output';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output | TABLE |
+---------------+-------+
1 row in set (0.01 sec)
查看查詢日志信息。
mysql> select * from mysql.general_log;
+---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
| event_time | user_host | thread_id | server_id | command_type | argument |
+---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
| 2017-07-06 12:32:05 | root[root] @ localhost [] | 1 | 1 | Query | show variables like 'general%' |
| 2017-07-06 12:32:28 | root[root] @ localhost [] | 1 | 1 | Query | show variables like 'log_output' |
| 2017-07-06 12:32:41 | root[root] @ localhost [] | 1 | 1 | Query | select * from MyDB.test |
| 2017-07-06 12:34:36 | [root] @ localhost [] | 3 | 1 | Connect | root@localhost on |
| 2017-07-06 12:34:36 | root[root] @ localhost [] | 3 | 1 | Query | KILL QUERY 1 |
| 2017-07-06 12:34:36 | root[root] @ localhost [] | 3 | 1 | Quit | |
| 2017-07-06 12:34:51 | root[root] @ localhost [] | 1 | 1 | Query | select * from mysql.general_log |
+---------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
7 rows in set (0.02 sec)
本文標題:Linux下查看mysql數(shù)據(jù)庫操作記錄具體方法
網站地址:http://m.fisionsoft.com.cn/article/cdoooop.html


咨詢
建站咨詢
