Mysql对用户操作加审计功能——高级版
1:创建登录日志库,登录日志表
CREATE DATABASE `accesslog`;
USE `accesslog`;
CREATE TABLE `accesslog`
(`id` int(11) NOT NULL AUTO_INCREMENT,`thread_id` int(11) DEFAULT NULL, #线程ID,这个值很重要`log_time` timestamp NOT NULL DEF AULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, #登录时间`localname` varchar(30) DEFAULT NULL, #登录名称`matchname` varchar(30) DEFAULT NULL, #登录用户PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
init-connect='insert into accesslog.accesslog values(null,connection_id(),now(),user(),current_user());'
grant insert,select,update on *.* to 'user1'@'localhost'; #带INSERT权限
grant select,update on *.* to 'user2'@'localhost'; #不带INSERT权限
D:\mysql6\bin>mysql -uuser1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 65
Server version: 5.1.45-community-log MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select * FROM accesslog.accesslog;
+----+-----------+---------------------+-----------------+-----------------+
| id | thread_id | log_time | localname | matchname |
+----+-----------+---------------------+-----------------+-----------------+
| 1 | 65 | 2011-03-11 19:18:25 | user1@localhost | user1@localhost |
+----+-----------+---------------------+-----------------+-----------------+
1 row in set (0.00 sec)
mysql> show processlist;
+----+-------+----------------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------+----------------+------+---------+------+-------+------------------+
| 65 | user1 | localhost:1339 | NULL | Query | 0 | NULL | show processlist |
+----+-------+----------------+------+---------+------+-------+------------------+
1 row in set (0.00 sec)
mysql>
D:\mysql6\bin>mysql -uuser2 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 76
Server version: 5.1.45-community-log
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select * FROM accesslog.accesslog;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 77
Current database: *** NONE ***
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> select * FROM accesslog.accesslog;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 78
Current database: *** NONE ***
110311 19:23:47 [Warning] Aborted connection 77 to db: 'unconnected' user: 'user2' host: 'localhost' (init_connect command failed)
110311 19:23:47 [Warning] INSERT command denied to user 'user2'@'localhost' for table 'accesslog'
110311 19:23:53 [Warning] Aborted connection 78 to db: 'unconnected' user: 'user2' host: 'localhost' (init_connect command failed)
110311 19:23:53 [Warning] INSERT command denied to user 'user2'@'localhost' for table 'accesslog'
mysql> insert into t3 values(10,10,'2011-10-10 00:00:00');
Query OK, 1 row affected (0.00 sec)
mysql> show processlist;
+----+-------+----------------+-----------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------+----------------+-----------+---------+------+-------+------------------+
| 69 | user1 | localhost:1439 | accesslog | Query | 0 | NULL | show processlist |
+----+-------+----------------+-----------+---------+------+-------+------------------+
1 row in set (0.00 sec)
mysql> select * from accesslog.accesslog;
+----+-----------+---------------------+-----------------+-----------------+
| id | thread_id | log_time | localname | matchname |
+----+-----------+---------------------+-----------------+-----------------+
| 1 | 65 | 2011-03-11 19:18:25 | user1@localhost | user1@localhost |
| 2 | 91 | 2011-03-11 19:28:33 | user1@localhost | user1@localhost |
| 3 | 2 | 2011-03-11 19:31:49 | user1@localhost | user1@localhost |
| 4 | 2 | 2000-10-10 10:10:10 | user1@localhost | user1@localhost |
| 5 | 21 | 2000-10-10 11:11:11 | root@localhost | root@% |
| 6 | 69 | 2011-03-12 21:35:43 | user1@localhost | user1@localhost |
+----+-----------+---------------------+-----------------+-----------------+
6 rows in set (0.01 sec)
# at 340
#110312 21:36:01 server id 1 end_log_pos 453 Query thread_id=69 exec_time=0 error_code=0
use text/*!*/;
SET TIMESTAMP=1299936961/*!*/;
insert into t3 values(10,10,'2011-10-10 00:00:00')
/*!*/;
# at 453
在日志表里记录的和日志文件里面记录的相同。可以通过这个thread_id来追踪到是谁,什么时间,做了什么操作。
转载于:https://www.cnblogs.com/zuoxingyu/p/3990585.html
Mysql对用户操作加审计功能——高级版相关推荐
- mysql利用init-connect增加访问审计功能的实现
mysql的连接首先都是要通过init-connect初始化,然后连接到实例. 我们利用这一点,通过在init-connect的时候记录下用户的thread_id,用户名和用户地址实现db的访问审计功 ...
- mysql基于init-connect+binlog完成审计功能
目前社区版本的mysql的审计功能还是比较弱的,基于插件的审计目前存在于Mysql的企业版.Percona和MariaDB上,但是mysql社区版本有提供init-connect选项,基于此我们可以用 ...
- mysql中用户操作日志_Mysql 纪录用户操作日志
我们想追踪某个数据库操作记录,如想找出是谁操作了某个表(比如谁将字段名改了). 二进制日志记录了操作记录,线程号等信息,但是却没有记录用户信息,因此需要结合init-connect来实现追踪. ini ...
- Centos系统添加系统用户操作记录审计
有时候我们需要对线上用户操作记录进行历史记录待出现问题追究责任人,,但Linux系统自带的history命令用户有自行删除权限,那怎么设置可以让用户的操作记录实时记录,并保证普通用户无权删除呢? 1. ...
- PO模型操作加购物车功能
- mysql所有的审计方法_mysql的审计功能
mysql的审计功能 mysql服务器自身没有提供审计功能,但是我们可以使用init-connect + binlog的方法进行mysql的操作审计.由于mysql binlog记录了所有对数据库长生 ...
- Ranger 和 Ranger Audit 审计功能模块介绍
目录 一.Ranger 介绍 1.Ranger概念 2.权限模型 二.Ranger Aduit审计功能模块详解 1.Ambari 中 Ranger config 2.Ranger Audit 功能模块 ...
- shiro mysql_Shiro系列之Shiro+Mysql实现用户认证(Authentication)
网上大多数介绍Apache Shiro的资料都是使用ini文件的简单配置为例,很少用讲到如何配合数据库来实现用户认证的.我也是刚刚开始接触Shiro,在这里介绍一个入门级别的Shiro+Mysql的配 ...
- 基于struts2拦截器实现用户操作日志记录
2019独角兽企业重金招聘Python工程师标准>>> 这里基于struts2的拦截器来实现. 使用struts2拦截器拦截所有或者指定的请求,对用户操作过程中的:操作用户,操作时间 ...
最新文章
- python提示错误TypeError: 'dict_keys' object does not support indexing
- ImageUploadAssist--DATA
- 美!视差滚动在图片滑块中的应用【附源码下载】
- 入网许可证_入网许可证怎么办理,申请流程
- Spring中的@Cacheable开销
- 注入dll到explorer.exe中无反应_MBR膜生物反应器的安装及技术要求都有什么呢?
- 1.2 Coin 项目
- 基于Tesseract的Android OCR应用程序
- websocket连接出现 HTTP Authentication failed; no valid credentials available
- 韩城市财政局党委举办“信心比金子还重要”演讲赛-渤锐软件提供相关软件支持
- Protel99se 犯的错误
- yandex安装插件教程,研究了一下午终于可以用了
- vue-aliplayer 阿里云播放器适配 vue
- Python-while 计算100以内奇数和
- 大学本科计算机专业的课程
- 计算机应用bsp什么意思,bsp文件是什么?bsp文件怎么打开?
- 菜鸟学IT之Hadoop综合大作业
- android中android:wight详解
- win10修改用户名(中文用户改为英文名)切换administrators管理员用户
- 积木拼图游戏-积木游戏世界中文版
热门文章
- matlab 归一化_MATLAB主成分PCA人脸识别深度解析(一)
- python pca降维_机器学习之sklearn中的降维算法
- BootStrap笔记-分页
- 系统架构师学习笔记-多媒体基础知识
- Qt学习笔记-仿大佬读取setting文件(简单工厂模式)
- C++工作笔记-Windows下查找窗口句柄并让其显示在桌面
- Database工作笔记-对层次库的理解
- python装饰器使用多吗_如何理解Python装饰器?
- (王道408考研数据结构)第五章树-第三节2:二叉树构造和重建
- (计算机组成原理)第四章指令系统-第二节1:指令寻址