如何修改审计日志的表结构?
原表结构:
start_time
开始执行的时间user_host
登陆的用户名和hostquery_time sql
执行的时间rows
返回结果集行数db sql
执行的当前数据库名sql_text sql
内容conn_type
用户登陆方式(CAPI、ODBC、JDBC、ADO)审计日志表新增列的内容如下:Taskid
全局唯一的任务号End_time
SQL执行结束的时间Sql_type
标识SQL类型,DDL,DML,DQL,OTHERSStatus
标识SQL执行成功还是失败,SUCCESS,FAILED
项目上手动修改表结构。
2)修改审计日志表结构时需要关闭审计日志功能,
set global audit_log=off;
3)修改审计日志表结构之前需要执行:
set sql_mode=’’;
4)修改表结构有两种方法
- 方法一,直接在原表上增加列
Alter self table audit_log add column taskid bigint not null first;
Alter self table audit_log add column end_time timestamp not null after start_time;
Alter self table audit_log add column sql_type mediumtext not null after sql_text;
Alter self table audit_log add column status mediumtext not null after sql_type; - 方法二,创建新表,倒数据后,替换原表
Taskid bigint not null,
Start_time timestamp not null,
End_time timestamp not null,
User_host mediumtext not null,
Query_time time not null,
Rows integer not null,
Db varchar(512) not null,
Sql_text mediumtext not null,
Sql_type mediumtext not null,
Status mediumtext not null,
Conn_type mediumtext not null
) engine =gssys character set utf8 comment=’Audit log’;
Insert into audit_log_new(start_time, user_host, query_time, rows, db, sql_text, conn_type) select * from audit_log;
Alter self table audit_log rename to audit_log_bak;
Alter self table audit_log_new rename to audit_log;
5)替换完成后需要重新开启审计日志功能:set global audit_log=on;