Skip to content

Instantly share code, notes, and snippets.

@anytizer
Last active April 22, 2020 01:37
Show Gist options
  • Save anytizer/30c315ddfdb0fc703adcace9983497a2 to your computer and use it in GitHub Desktop.
Save anytizer/30c315ddfdb0fc703adcace9983497a2 to your computer and use it in GitHub Desktop.
USE test;
DROP TABLE IF EXISTS apache_logs;
CREATE TABLE apache_logs (
log_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Log ID',
processing_time INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Processing time in milliseconds',
http_status INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'HTTP status code',
request_method VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'Request URL (GET/POST)',
access_url TEXT NOT NULL COMMENT 'URLs accessed',
PRIMARY KEY (log_id)
);
<IfModule log_config_module>
LogFormat "%D %>s %m %U%q" urlsdetails
CustomLog "logs/access-urls-details.log" urlsdetails
</IfModule>
TRUNCATE apache_logs;
-- Load the Apache Log into MySQL Database
-- You may use full path eg: C:\\xampp\\apache\\logs\\access-urls-details.log
LOAD DATA LOCAL INFILE 'access-urls-details.log'
INTO TABLE apache_logs
FIELDS ESCAPED BY '\\' TERMINATED BY ' '
LINES TERMINATED BY '\r\n' (processing_time, http_status, request_method, access_url);
SELECT * FROM apache_logs;
SELECT * FROM apache_logs ORDER BY processing_time DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment