测试脚本:
CREATE TABLE log_xyz.accesslog (`id` int(11) primary key auto_increment,conn_id int, `time` timestamp, `localname` varchar(30), `matchname` varchar(30));
grant all privileges on log_xyz.* to 'xyz'@'%' identified by '******';
下面参数设置,必须授予非操作用户插入log_xyz.accesslog的权限,否则,会导致报错,无法使用数据库。
在参数文件设置如下:
init-connect='insert into log_xyz.accesslog(conn_id,time,localname,matchname) values(connection_id(),now(),user(),current_user());'
若是在mysql客户端命令如下:
set global init_connect='insert into log_xyz.accesslog(conn_id,time,localname,matchname) values(connection_id(),now(),user(),current_user());';
使用xyz登录并truncate t_xyz2表,
[mysql@zdzxdb02 ~]$ mysql -uxyz -p****** -h172.16.11.89 -P3306
mysql> use log_xyz;
mysql> truncate table t_xyz2;
Query OK, 0 rows affected (0.01 sec)
通过binlog日志:
mysqlbinlog binlog.000003>3.sql
cat 3.sql
查看日志:
# at 890
#150105 9:45:56 server id 2 end_log_pos 977 Query thread_id=845 exec_time=0 error_code=0
SET TIMESTAMP=1420422356/*!*/;
truncate table t_xyz2
/*!*/;
DELIMITER ;
# End of log file
thread_id=845和log_xyz.accesslog的登录时间段差不多有记录。
root@localhost:log_xyz 09:44:50> select * from accesslog;
+-----+---------+---------------------+------------------+----------------+
| id | conn_id | time | localname | matchname |
+-----+---------+---------------------+------------------+----------------+
| 825 | 845 | 2015-01-05 09:45:09 | xyz@172.16.11.89 | xyz@% |
+-----+---------+---------------------+------------------+----------------+
这证明是xyz@%用户操作,登录主机是172.16.11.89。
审计对dba本身没用
而非dba的人只要加强权限管理就行,业务和运维账号实现最小权限原则,宁愿操作麻烦,确保数据安全。
对于连接不是非常频繁的数据库来说,增加写入日志功能,对性能影响不大。
CREATE TABLE log_xyz.accesslog (`id` int(11) primary key auto_increment,conn_id int, `time` timestamp, `localname` varchar(30), `matchname` varchar(30));
grant all privileges on log_xyz.* to 'xyz'@'%' identified by '******';
下面参数设置,必须授予非操作用户插入log_xyz.accesslog的权限,否则,会导致报错,无法使用数据库。
在参数文件设置如下:
init-connect='insert into log_xyz.accesslog(conn_id,time,localname,matchname) values(connection_id(),now(),user(),current_user());'
若是在mysql客户端命令如下:
set global init_connect='insert into log_xyz.accesslog(conn_id,time,localname,matchname) values(connection_id(),now(),user(),current_user());';
使用xyz登录并truncate t_xyz2表,
[mysql@zdzxdb02 ~]$ mysql -uxyz -p****** -h172.16.11.89 -P3306
mysql> use log_xyz;
mysql> truncate table t_xyz2;
Query OK, 0 rows affected (0.01 sec)
通过binlog日志:
mysqlbinlog binlog.000003>3.sql
cat 3.sql
查看日志:
# at 890
#150105 9:45:56 server id 2 end_log_pos 977 Query thread_id=845 exec_time=0 error_code=0
SET TIMESTAMP=1420422356/*!*/;
truncate table t_xyz2
/*!*/;
DELIMITER ;
# End of log file
thread_id=845和log_xyz.accesslog的登录时间段差不多有记录。
root@localhost:log_xyz 09:44:50> select * from accesslog;
+-----+---------+---------------------+------------------+----------------+
| id | conn_id | time | localname | matchname |
+-----+---------+---------------------+------------------+----------------+
| 825 | 845 | 2015-01-05 09:45:09 | xyz@172.16.11.89 | xyz@% |
+-----+---------+---------------------+------------------+----------------+
这证明是xyz@%用户操作,登录主机是172.16.11.89。
审计对dba本身没用
而非dba的人只要加强权限管理就行,业务和运维账号实现最小权限原则,宁愿操作麻烦,确保数据安全。
对于连接不是非常频繁的数据库来说,增加写入日志功能,对性能影响不大。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29114615/viewspace-1408342/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29114615/viewspace-1408342/
本文探讨了在数据库中为非操作用户授予插入权限的方法,包括参数设置、MySQL客户端命令及安全策略。通过实例展示了如何确保数据安全的同时,避免性能瓶颈。
1486

被折叠的 条评论
为什么被折叠?



