MySQL利用init-connect增加访问审计功能异常
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,init-connet设置注:该参数对超级用户不生效-- 创建测试库mysql> create database test;Query OK, 1 row affected (0.00 sec)mys
千家信息网最后更新 2025年11月07日MySQL利用init-connect增加访问审计功能异常
init-connet设置
注:该参数对超级用户不生效
-- 创建测试库mysql> create database test;Query OK, 1 row affected (0.00 sec)mysql> use test;Database changed-- 创建审计记录表mysql> CREATE TABLE `conn_log` ( -> `conn_id` int(11) DEFAULT NULL, -> `conn_time` datetime DEFAULT NULL, -> `user_name` varchar(128) CHARACTER SET utf8 DEFAULT NULL, -> `cur_user_name` varchar(128) CHARACTER SET utf8 DEFAULT NULL, -> `ip` varchar(15) CHARACTER SET utf8 DEFAULT NULL, -> KEY `conn_time` (`conn_time`) -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;Query OK, 0 rows affected (0.01 sec)-- 设置审计内容mysql> set global init_connect="set @user=user(),@cur_user=current_user();insert into test.conn_log values(connection_id(),now(),@user,@cur_user,'10.0.0.1');" -> ;Query OK, 0 rows affected (0.00 sec)mysql> show variables like '%init%';+------------------------+-------------------------------------------------------------------------------------------------------------------------------+| Variable_name | Value |+------------------------+-------------------------------------------------------------------------------------------------------------------------------+| init_connect | set @user=user(),@cur_user=current_user();insert into test.conn_log values(connection_id(),now(),@user,@cur_user,'10.0.0.1'); || init_file | || init_slave | || table_definition_cache | 1400 |+------------------------+-------------------------------------------------------------------------------------------------------------------------------+4 rows in set (0.00 sec)-- 创建普通用户mysql> grant select,insert on dba_test.* to 'test'@'%' identified by 'test';Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.01 sec)异常
[root@test ~]# mysql -S /data0/mysql57/mysql3307/mysqltmp/mysql3307.sock -utest -ptest Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 117Server version: 5.7.21-logCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show user();ERROR 2006 (HY000): MySQL server has gone awayNo connection. Trying to reconnect...Connection id: 118Current database: *** NONE ***ERROR 1184 (08S01): Aborted connection 118 to db: 'unconnected' user: 'test' host: 'localhost' (init_connect command failed)mysql> select user();ERROR 2006 (HY000): MySQL server has gone awayNo connection. Trying to reconnect...Connection id: 119Current database: *** NONE ***异常处理
分析
通过查看erro log发现test用户没有test.conn_log表的写权限,导致init-connect中的sql内容无法进行,
从而导致连接失败
解决
-- 赋权mysql> grant insert on test.* to 'test'@'%';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)-- 登陆正常[root@test ~]# mysql -hip地址 -P3307 -utest -ptestWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 140Server version: 5.7.21-log MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use dba_test;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> show tables;+--------------------+| Tables_in_dba_test |+--------------------+| user |+--------------------+1 row in set (0.00 sec)mysql> insert into user(user_id,username) values(4,'d');Query OK, 1 row affected (0.00 sec)mysql>
用户
审计
内容
普通
参数
地址
权限
记录表
赋权
分析
处理
测试
登陆
功能
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
服务器中如何制作32k村民
密码编码学与网络安全学习
国家网络安全态势感知
2016安装数据库出现错误
信息基础设施网络安全保护
数据库怎样设置类型长度
甘肃网络安全工作报告
燃烧的远征龙牙服务器
tk网络安全
百度地图 软件开发
农村地区网络安全监测
电商线上商城软件开发价格
最新网络技术科技
开启转发服务器
cbm数据库无法检索
武汉参考网络安全维护资费
电脑远程监控软件开发公司
pptp服务器已达容量限制
安装用友下载的数据库u8
网络安全必学渗透测试流程
动态添加数据库字段
对数据库原理课程的期望
接口布到服务器上
库存监控软件开发
数据库文件夹默认磁盘目录下
东北大学数据库习题
软件开发者平台层吗
辅助制作和软件开发
数据库技能练习题下载
计算机软件开发实习生工资