MySQL uses init-connect to increase access audit feature anomalies

Source: Internet
Author: User
Tags flush reserved

Init-connet Settings Note: This parameter does not take effect for super users
--Creating a test library mysql> create database test; Query OK, 1 row Affected (0.00 sec) mysql> use test;database changed--creating audit record table mysql> create table ' Conn_log ' (-&G   T ' conn_id ' int (one) default null, ' Conn_time ' datetime default NULL, ' user_name ' varchar (+) CHARACTE R set UTF8 default null, ' Cur_user_name ' varchar ($) CHARACTER SET UTF8 default null, ' IP ' varchar ( CHARACTER SET UTF8 default NULL, KEY ' conn_time ' (' conn_time ') engine=innodb default Charset=utf 8MB4; Query OK, 0 rows affected (0.01 sec)--set audit content 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)--Create a regular user 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)
Abnormal
[[email protected] ~]# 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 ***
Exception Handling Analysis

Because the test user does not have write access to the Test.conn_log table, it cannot be audited, so the error

Solve
--Empowering 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)--landing normal [[email protected] ~]# mysql-hip address-p3307-utest-ptestwelcome to the My  SQL Monitor. Commands End With; or \g.your MySQL connection ID is 140Server version:5.7.21-log mysql Community Server (GPL) Copyright (c), Orac Le and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names 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 W Ith-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>

MySQL uses init-connect to increase access audit feature exceptions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.