您的位置:首页 > 数据库 > SQL

监控/审计有哪些用户连接mysql数据库 init_connect

2010-11-18 22:49 316 查看
监控/审计有哪些用户连接mysql数据库
2010-08-19 18:18
不开启查询日志,监控/审计有哪些用户连接mysql数据库 init_connect 释义: Client端每次连接到数据库时,MySQL会先执行init_connect里面指定的一个或者多个sql语句。 注意点: 1.当拥有SUPER权限的用户连接时,init_connect设定的sql语句不会被执行 2.务必保证init_connect设定的sql语句没有任何错误,要不然连接会出错。 3.此参数可以让局部变量像全局变量那在配置文件设置属性: 全局、字符串、可动态修改 一.示例1 SET GLOBAL init_connect='SET AUTOCOMMIT=0'; 还可以在命令行或选项文件中设置该变量。要想使用选项文件设置变量,应包括下述行: [mysqld] init_connect='SET AUTOCOMMIT=0' 请注意init_connect的内容并不为拥有SUPER权限的用户执行;实际是内容设置错误(包含错误查询,例如语法错误),这样使所有连接失败。不为SUPER用户执行,使SUPER用户可以打开连接并固定init_connect。 二、示例2 此参数可以用于做登陆审计。 mysql> TABLE `wsz` ( `i` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`i`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 mysql> SET GLOBAL init_connect="SET AUTOCOMMIT=0;insert into test.wsz values ('');"; Query OK, 0 rows affected (0.00 sec) 退出后用普通用户登陆: [seezoo@dbaview.cn ~]$ /home/seezoo/mysql/mysql50134/bin/mysql -S /home/seezoo/mysql/mysql50134/mysql.sock Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 25 Server version: 5.1.34 Source distribution Type 'help;' or '/h' for help. Type '/c' to clear the current input statement. mysql> select @@autocommit; +--------------+ | @@autocommit | +--------------+ | 0 | +--------------+ 1 row in set (0.00 sec) mysql> select * from test.wsz; +---+ | i | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | +---+ 5 rows in set (0.00 sec) 用root用户登陆后发现相关值没修改: [seezoo@dbaview.cn ~]$ /home/seezoo/mysql/mysql50134/bin/mysql -uroot -S /home/seezoo/mysql/mysql50134/mysql.sock Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 26 Server version: 5.1.34 Source distribution Type 'help;' or '/h' for help. Type '/c' to clear the current input statement. mysql> select * from test.wsz; +---+ | i | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | +---+ 5 rows in set (0.00 sec) mysql> select @@autocommit; +--------------+ | @@autocommit | +--------------+ | 1 | +--------------+ 1 row in set (0.00 sec) [seezoo@dbaview.cn ~]$ /home/seezoo/mysql/mysql50134/bin/mysql -S /home/seezoo/mysql/mysql50134/mysql.sock Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 27 Server version: 5.1.34 Source distribution Type 'help;' or '/h' for help. Type '/c' to clear the current input statement. mysql> select @@autocommit; +--------------+ | @@autocommit | +--------------+ | 0 | +--------------+ 1 row in set (0.00 sec) mysql> select * from test.wsz; +---+ | i | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | +---+ 6 rows in set (0.00 sec)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: