首先修改apache的配置文件,在配置文件里找到LogFormat和CustomLog,注销原来的,替换成以下内容
LogFormat "INSERT INTO apachelog (ID, dateTime, IP, URL, code, referer, userAgent, size, request) VALUES ( NULL , ”%{%Y-%m-%d %H:%M:%S}t”, ”%a”, ”%U”, ”%>s”, ” %{Referer}i”, ”%{User-Agent}i”, %b, %T);" sqlcomm CustomLog "| /usr/bin/MySQL --user=root --password='123456' --database=test" sqlcomm
注意上面连接mysql的配置要修改
创建一个数据库如test,创建一个表,如下sql
CREATE TABLE `apachelog` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `dateTime` datetime NOT NULL, `IP` varchar(15) NOT NULL, `URL` varchar(256) NOT NULL, `code` varchar(3) NOT NULL, `referer` varchar(256) NOT NULL, `userAgent` varchar(256) NOT NULL, `size` int(11) NOT NULL, `request` float NOT NULL, PRIMARY KEY (`ID`), KEY `dateTime` (`dateTime`) ) ENGINE=MyISAM AUTO_INCREMENT=40;