hue审计记录-记录用户的查询记录(用户前端删除,后端也不会删除)

 原来用户执行sql会存储在desktop_document2表中,用户可以在前端界面对其进行删除,为了优化审计,建立一个新表desktop_document2_history,并建立一个触发器,实时更新。

添加一个触发器,记录所有用户的执行sql

DROP TABLE IF EXISTS `desktop_document2_history`;
CREATE TABLE `desktop_document2_history` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `desktop_document2_id` bigint(20) NOT NULL,
  `owner_id` bigint(20) NOT NULL,
  `create_time` datetime  NOT NULL,
  `search` longtext,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TRIGGER IF EXISTS `tri_update_desktop_document2`;
DELIMITER ;;
CREATE TRIGGER `tri_update_desktop_document2` 
AFTER UPDATE ON `desktop_document2` FOR EACH ROW begin
    INSERT INTO desktop_document2_history
         (desktop_document2_id,owner_id,create_time, search) VALUES (new.id,new.owner_id, new.last_modified, new.search);
end
;;
DELIMITER ;