Parse Apache Log Files into a MySQL database

Sometimes you have a lot of log files that are hard to search using a text editor either because of the size or you want to do more complicated queries. You can quite easily load an Apache log file into a database to allow easy searching, and even allows you to generate useful statistics.

The info below is based on a standard Apache 2.2 installation, the log file format may have changed in newer versions of Apache, but the principles will still apply.

Create table to hold the log data

Import the data file

You can run this for multiple files if needed.

That’s it really!

Useful queries

You can query the data however you like, e.g.

Most requested files

Most requested html files