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
Mysql对用户操作加审计功能——高级版的更多相关文章
- Mysql对用户操作加审计功能——初级版
在某些应用里,需要知道谁对表进行了操作,进行了什么操作,所为责任的追朔.在MYSQL里,可以使用触发器实现. 1:创建测试表 mysql> create table A(a int);Query ...
- 【转】mysql利用init-connect增加访问审计功能
mysql的连接首先都是要通过init-connect初始化,然后连接到实例. 我们利用这一点,通过在init-connect的时候记录下用户的thread_id,用户名和用户地址实现db的访问审计功 ...
- mysql基于init-connect+binlog完成审计功能
目前社区版本的mysql的审计功能还是比较弱的,基于插件的审计目前存在于Mysql的企业版.Percona和MariaDB上,但是mysql社区版本有提供init-connect选项,基于此我们可以用 ...
- linux下用户操作记录审计环境的部署记录
通常,我们运维管理人员需要知道一台服务器上有哪些用户登录过,在服务器上执行了哪些命令,干了哪些事情,这就要求记录服务器上所用登录用户的操作信息,这对于安全维护来说很有必要.废话不多说了,下面直接记录做 ...
- Mysql 纪录用户操作日志
有时,我们想追踪某个数据库操作记录,如想找出是谁操作了某个表(比如谁将字段名改了). 二进制日志记录了操作记录,线程号等信息,但是却没有记录用户信息,因此需要结合init-connect来实现追踪. ...
- mysql 命令行操作入门(详细讲解版)
之前分享过多次Mysql主题,今天继续分享mysql命令行入门 1. 那么多mysql客户端工具,为何要分享命令行操作? -快捷.简单.方便 -在没有客户端的情况下怎么办 -如果是mysql未开启 ...
- mysql 之审计 init-connect+binlog完成审计功能
mysql基于init-connect+binlog完成审计功能 目前社区版本的mysql的审计功能还是比较弱的,基于插件的审计目前存在于Mysql的企业版.Percona和MariaDB上,但是my ...
- 如何实现MySQL数据库使用情况的审计
如何实现MySQL数据库使用情况的审计 最佳答案 mysql的审计功能 mysql服务器自身没有提供审计功能,但是我们可以使用init-connect + binlog的方法进行mysql的操 ...
- mysql创建用户以及授权
Mysql新建用户操作 方法一: mysql> insert into mysql.user(Host,User,Password) values("localhost", ...
随机推荐
- apache log4j日志工具使用入门[maven 项目配置]
简单的介绍下Maven项目中有关org.apache.log4j.Logger的使用.[1]首先我们需要找到 org.apache.log4j.Logger的坐标,并配置到POM.xml <de ...
- eclipse 本地项目提交到远程库以及从远程库中添加项目 ---git
本地项目提交到远程库 1.右击项目->team->share project 2.选择本地库 从远处库中的项目拉到本地 1.右击项目->import项目
- visual studio 远程服务器返回了意外响应:(417)expectation failed
解决方法: 修改devenv.exe.config文件,添加 <servicePointManager expect100Continue="false" /> C:\ ...
- IBatis.Net XML文件配置
一.添加Provider.config <?xml version="1.0" encoding="utf-8"?> <providers x ...
- 在服务器端将XML转换成HTML
以下是在服务器上转换XML文件所需要的简单源代码: <% 'Load the XML set xml = Server.CreateObject("Microsoft.XMLDOM&q ...
- python3使用requests登录人人影视网站
python3使用requests登录人人影视网站 继续练习使用requests登录网站,人人影视有一项功能是签到功能,需要每天登录签到才能升级. 下面的代码python代码实现了使用requests ...
- ETL工具与脚本实现之间的对比
scripts, custom code and individual vs. team development doesn’t scale And: ‣Lack of coding standard ...
- 3、通过挂在系统光盘搭建本地yum仓库的方法
1. mkdir xxx #新建文件夹 (新建一个挂载需要的文件夹) .配置本地yum源(挂载光盘) .进入 yum.repos.d .ls (查看当前文件夹全部的文件) 并 mv 修改 除Med ...
- BOM和DOM(精简版)
一.BOM 1.browser object model的缩写,简称浏览器对象模型 2.提供与浏览器窗口进行交互的对象 3.核心对象:window.除此之外还有:history,localtion,n ...
- html、css、js注释
HTML注释 <!--注释的内容--> CSS注释 /* 注释内容 */ JS注释 单行注释以 // 开头. 多行注释以 /* 开始,以 */ 结尾.