Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

การใช้ MySQL กับ Apache

Apache = web server software พัฒนาโดย Apache Software Foundation รับ requests จาก user เข้าถึง web page

ทำ security checks บน HTTP request แล้วส่ง user ไป web page มีหลายโปรแกรม authenticate users จาก MySQL database และเขียน log files ลง MySQL table

เปลี่ยน Apache logging format ให้ readable ด้วย MySQL ใส่ code ใน Apache config file:

LogFormat \
 "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",
 \"%U\",\"%{Referer}i\",\"%{User-Agent}i\"

Load log file ใน format นี้เข้า MySQL:

LOAD DATA INFILE '/local/access_log' INTO TABLE tbl_name
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'

Table ต้องมี columns ตรงกับ LogFormat line ที่เขียนใน log file