mysql查詢日誌
mysql查詢日誌是用來記錄使用者登入資料庫、記錄使用者在資料庫操作的日誌。類似oracle的審計功能,但是出於線上資料庫頻繁的操作,會產生大量的IO和磁碟空間的壓力,mysql是預設關閉的。但是有時候出於安全的考慮需要開啟,
這就要在安全和效率之間權衡了。
mysql> show global variables like '%general_log%';
+------------------+----------------------------------------+
| Variable_name | Value |
+------------------+----------------------------------------+
| general_log | OFF | --關閉狀態
| general_log_file | /data/DB/mysql/trcloud-gtt-test-db.log | --查詢日誌名稱
+------------------+----------------------------------------+
2 rows in set (0.00 sec)
mysql>set global general_log=on;
mysql> show global variables like '%general_log%';
+------------------+----------------------------------------+
| Variable_name | Value |
+------------------+----------------------------------------+
| general_log | ON | --開啟狀態
| general_log_file | /data/DB/mysql/trcloud-gtt-test-db.log | --查詢日誌名稱
+------------------+----------------------------------------+
現在來看看這些查詢日誌都有哪些資訊
登入資料庫進行一番操作
[root@trcloud-wujian-test01 mysql]# mysql -P3306 -h172.30.249.154 -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'172.30.248.18' (using password: YES) --- 登入失敗
[root@trcloud-wujian-test01 mysql]# mysql -P3306 -h172.30.249.154 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 191
Server version: 5.6.27-76.0-log Percona Server (GPL), Release 76.0, Revision 5498987
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test; -- 選擇資料庫
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from emp; --查詢
+------+------+
| id | name |
+------+------+
| 1 | jx |
+------+------+
1 row in set (0.00 sec)
mysql> drop table emp; -- 刪除
Query OK, 0 rows affected (0.04 sec)
mysql> ^CCtrl-C -- exit! --退出
Aborted
[root@trcloud-wujian-test01 mysql]
開啟查詢日誌
[root@trcloud-gtt-test-db mysql]# tail -50f trcloud-gtt-test-db.log
160412 14:18:45 190 Connect root@172.30.248.18 on --從哪個IP用什麼使用者登入失敗記錄
190 Connect Access denied for user 'root'@'172.30.248.18' (using password: YES)
160412 14:19:12 191 Connect root@172.30.248.18 on --記錄從哪個IP哪個使用者何時登入,191是一個session的唯一表示,同一個session這個數字是一致的
191 Query select @@version_comment limit 1
160412 14:19:24 191 Query SELECT DATABASE()
191 Init DB test
191 Query show databases
191 Query show tables
191 Field List emp
160412 14:19:33 191 Query select * from emp --查詢操作
160412 14:19:40 191 Query drop table emp --刪除操作
160412 14:20:18 191 Quit --退出session
這就要在安全和效率之間權衡了。
mysql> show global variables like '%general_log%';
+------------------+----------------------------------------+
| Variable_name | Value |
+------------------+----------------------------------------+
| general_log | OFF | --關閉狀態
| general_log_file | /data/DB/mysql/trcloud-gtt-test-db.log | --查詢日誌名稱
+------------------+----------------------------------------+
2 rows in set (0.00 sec)
mysql>set global general_log=on;
mysql> show global variables like '%general_log%';
+------------------+----------------------------------------+
| Variable_name | Value |
+------------------+----------------------------------------+
| general_log | ON | --開啟狀態
| general_log_file | /data/DB/mysql/trcloud-gtt-test-db.log | --查詢日誌名稱
+------------------+----------------------------------------+
現在來看看這些查詢日誌都有哪些資訊
登入資料庫進行一番操作
[root@trcloud-wujian-test01 mysql]# mysql -P3306 -h172.30.249.154 -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'172.30.248.18' (using password: YES) --- 登入失敗
[root@trcloud-wujian-test01 mysql]# mysql -P3306 -h172.30.249.154 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 191
Server version: 5.6.27-76.0-log Percona Server (GPL), Release 76.0, Revision 5498987
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test; -- 選擇資料庫
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from emp; --查詢
+------+------+
| id | name |
+------+------+
| 1 | jx |
+------+------+
1 row in set (0.00 sec)
mysql> drop table emp; -- 刪除
Query OK, 0 rows affected (0.04 sec)
mysql> ^CCtrl-C -- exit! --退出
Aborted
[root@trcloud-wujian-test01 mysql]
開啟查詢日誌
[root@trcloud-gtt-test-db mysql]# tail -50f trcloud-gtt-test-db.log
160412 14:18:45 190 Connect root@172.30.248.18 on --從哪個IP用什麼使用者登入失敗記錄
190 Connect Access denied for user 'root'@'172.30.248.18' (using password: YES)
160412 14:19:12 191 Connect root@172.30.248.18 on --記錄從哪個IP哪個使用者何時登入,191是一個session的唯一表示,同一個session這個數字是一致的
191 Query select @@version_comment limit 1
160412 14:19:24 191 Query SELECT DATABASE()
191 Init DB test
191 Query show databases
191 Query show tables
191 Field List emp
160412 14:19:33 191 Query select * from emp --查詢操作
160412 14:19:40 191 Query drop table emp --刪除操作
160412 14:20:18 191 Quit --退出session
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29989552/viewspace-2079723/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql 日誌之慢查詢日誌MySql
- mysql 查詢日誌MySql
- mysql 日誌之普通查詢日誌MySql
- MySQL:慢查詢日誌MySql
- MySQL 通用查詢日誌MySql
- mysql慢查詢日誌MySql
- 關於MySQL 通用查詢日誌和慢查詢日誌分析MySql
- 【MySQL】慢查詢日誌不列印MySql
- mysqlsla 分析mysql慢查詢日誌MySql
- mysql之 slow log 慢查詢日誌MySql
- MySQL Slow Query log(慢查詢日誌)MySql
- mysql慢查詢日誌分析工具使用MySql
- Mysql慢查詢日誌分析工具mysqlslaMySql
- 【MySql】 慢日誌查詢工具之mysqlslaMySql
- 【MySql】mysql 慢日誌查詢工具之mysqldumpslowMySql
- PHP慢指令碼日誌和Mysql的慢查詢日誌PHP指令碼MySql
- MySQL慢查詢日誌相關設定MySql
- 【轉載】MySQL慢查詢日誌總結MySql
- mysql慢查詢和錯誤日誌分析MySql
- MYSQL開啟慢查詢日誌實施MySql
- mysql開啟檢視慢查詢日誌MySql
- 用命令過濾MySQL慢查詢日誌MySql
- Mysql慢查詢日誌檔案轉ExcelMySqlExcel
- MySQL資料庫中的日誌檔案---(3)慢查詢日誌MySql資料庫
- MySQL資料庫中的日誌檔案---(2)普通查詢日誌MySql資料庫
- mysql之 日誌體系(錯誤日誌、查詢日誌、二進位制日誌、事務日誌、中繼日誌)MySql中繼
- 對 MySQL 慢查詢日誌的簡單分析MySql
- 如何在MySQL中開啟慢查詢日誌?MySql
- mysql分析慢查詢日誌工具mysqlsla安裝MySql
- MySQL 慢查詢日誌——讓“慢”無所遁形MySql
- pt-query-digest分析mysql查詢日誌MySql
- Mysql 啟動慢查詢日誌 (不用重啟)MySql
- 分析mysql慢查詢日誌的好工具--mysqlslaMySql
- 資料庫MySQL一般查詢日誌或者慢查詢日誌歷史資料的清理資料庫MySql
- 日誌查詢錯誤
- 使用慢查詢日誌
- loki的日誌查詢Loki
- 開啟查詢慢查詢日誌引數