Created
July 24, 2014 13:33
-
-
Save marshallm/68218569215bc37e0e6e to your computer and use it in GitHub Desktop.
Login Audit SQL;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************* | |
* | |
* ADD THE FOLLOWING TO PRODUCTION my.cnf | |
* init_connect = "CALL <database>.login_audit()"; | |
* | |
*************************************************/ | |
/*CREATE TABLE FOR AUDIT DATA COLLECTION*/ | |
CREATE TABLE login_audit ( | |
audit_id SERIAL, | |
connection_id BIGINT, | |
user VARCHAR(255), | |
created_at TIMESTAMP | |
) ENGINE = MEMORY CHARSET = latin1; | |
/*CREATE PROCEDURE FOR AUDIT DATA COLLECTION*/ | |
DELIMITER $$ | |
CREATE PROCEDURE login_audit() | |
SQL SECURITY DEFINER | |
BEGIN | |
INSERT INTO login_audit | |
( | |
audit_id, | |
connection_id, | |
user, | |
created_at | |
) | |
VALUES | |
( | |
DEFAULT, | |
CONNECTION_ID(), | |
USER(), | |
CURRENT_TIMESTAMP() | |
); | |
END $$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment