说明:MYSQL的日志文件分成几种,通用查询日志便是其中的一种,通用查询日志可以用来记录用户的所有操作,包括启动和关闭MYSQL服务器、更新、查询等语句;
由于打开通用查询日志是记录用户的所有操作,在生产环境中这个日志的量是非常大的,所以一般情况下都是不打开的,myslq默认的该日志功能也是关闭的,在特殊情况下才进行打开;
一 、通用查询日志管理
1、状态的查看
mysql> show variables like 'general%';
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| general_log | OFF |
| general_log_file | /data/mysql/mysql.log |
+------------------+-----------------------+
2 rows in set (0.00 sec)
当前数据库的通用查询日志状态显示为关闭,日志路径为"/data/mysql/mysql.log"
2、通用查询日志的管理
mysql> show variables like 'general%';
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| general_log | OFF | 关闭状态
| general_log_file | /data/mysql/mysql.log | 默认路径和命名方式
+------------------+-----------------------+
2 rows in set (0.00 sec)
mysql> set global general_log=1; /启用脚本
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'general%';
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| general_log | ON | 显示已启用
| general_log_file | /data/mysql/mysql.log |
+------------------+-----------------------+
2 rows in set (0.00 sec)
mysql> set global general_log_file='/data/mysql/mysql_1.log'; 修改默认名称
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'general%';
+------------------+-------------------------+
| Variable_name | Value |
+------------------+-------------------------+
| general_log | ON |
| general_log_file | /data/mysql/mysql_1.log | 修改已生效
+------------------+-------------------------+
3、查看通用管理日志
准备工作,先做几个查询操作
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| retail |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql> use mysql
Database changed
mysql> select user,host,password from user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | mysql | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | mysql | |
+------+-----------+----------+
6 rows in set (0.00 sec)
做了以上操作之后,查看通用查询日志
[root@mysql mysql]# cat mysql_1.log
/usr/local/mysql/bin/mysqld, Version: 5.5.36-log (Source distribution). started with:
Tcp port: 3306 Unix socket: /tmp/mysql.sock
Time Id Command Argument
140829 11:36:58 1 Query show variables like 'general%'
140829 11:37:04 1 Quit
140829 11:41:13 2 Connect root@localhost on
2 Query select @@version_comment limit 1
140829 11:41:26 2 Query show databases
140829 11:41:29 2 Query SELECT DATABASE()
2 Init DB mysql
140829 11:41:44 2 Query select user,host,password from user
140829 11:42:23 2 Quit
可以看到,刚才的所有操作都被记录在日志文件中了。
4、删除通用查询日志
很简单,只有一条命令:mysqladmin flush-logs(经测试,没有效果,直接在操作系统进行删除。)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
本文作者:JOHN
ORACLE技术博客:ORACLE 猎人笔记 数据库技术群:367875324 (请备注ORACLE管理 )
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++