Import web logs to MySQL database

Source: Internet
Author: User
Keywords datasheet blog this
Tags access aliyun analysis blog data datasheet direct function

Access analysis is an important SEO work, but statistics, analysis tools, after all, the function is for the public, many times the SEO needs some specific data, is http://www.aliyun.com/zixun/aggregation/10341.html "> Statistical analysis software, procedures can not provide. In this way, direct Web log analysis is the most appropriate, the log will record each visit, as long as their own will extract, combination, you can get the data you want.

It was a long time to talk to the star Arrow, and finally agreed to import the logs into the SQL database (MySQL & SQL Server), using SQL statement analysis is the most convenient and what kind of data you need, as long as you use the appropriate SQL commands.

My server is Linux, and without SQL Server, it's not going to happen again. Today to talk about this topic seriously search for a moment, found the use of MySQL analysis log The first step, recorded here.

The next method of analysis I will post in the blog, interested friends can pay attention to, at the same time, recruit proficient in SQL statements of friends, discuss the various methods of analysis, and share to other friends.

The implementation of importing web logs to MySQL database

1. Modify Apache Log format

To modify the Web log format:

Logformat combined%>A,%UI,%UN,[%TL], "%rm%ru http/%rv",%hs,%h ","%{user-agent}>h ",%ss:%sh

Understand a friend should see it, SQL needs to import a specific separator, the Apache log by default is a space-delimited, and some content (such as 200 610 in the status code) also contains spaces, which can not be accurately imported.

Changing the log format to comma-delimited can be an accurate import. You can also eliminate unwanted content in the log format and reduce the log file size, depending on your needs.

2, the establishment of mysql6184.html "> data table

drop table if exists weblog;
CREATE TABLE Weblog (
ID int unsigned auto_increment PRIMARY KEY not NULL,
L_date date,
L_time time,
C_IP varchar (15),
S_IP varchar (15),
S_port varchar (5),
Method varchar (10),
Path varchar (255),
Query varchar (255),
Status varchar (3),
Domain varchar (50),
System varchar (200)
);

Note: Above is just a MySQL data table structure example, no corresponding to the previous log format, do not copy the use directly!

Create a new database with the data table structure corresponding to the log format.

3, import log to MySQL

LOAD DATA INFILE '/log location/log file ' into TABLE weblog FIELDS terminated by ', ';

Weblog corresponds to the data table name above.

The second step is to analyze, as mentioned above, to share after the experience.

Also, find a. PL program that imports IIS logs into the MySQL database from the Internet, and the principle is interlinked, and the points needed are downloaded here (Readme.txt for use).

Author: Si Shu
Original: Import Web log to MySQL database
Copyright, reprint must be linked to the form of the author and the original source and retain this statement.

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.