IIS日志导出mysql

开启IIS日志

开启日志很简单,在网站的功能视图中,点击日志进入。

2020-05-13_165207_enable_iislog.png

查看IIS日志

导出IIS日志到Mysql

Log Parser可以将文本日志解析成sql格式(支持odbc访问的都可以)

下载mysql connector odbc

地址:mysql connector odbc

  1. win10 可以安装8.0或最新版本,如果是windonw server则根据其他odbc版本安装,比如5..版本
  2. windonw server服务器安装确保安装Microsoft Visual C++ 2015 Redistributable(x86)或者是2012-2013版本
  3. 一般是下载32位,因为logparser只适配32位的odbc驱动程序

配置数据源

win10 选择32位的odbc数据源

2020-05-13_163638_odbc_select.png

系统DSN添加你的mysql数据源:

2020-05-13_164115_odbc_mysql.png

注意

  1. 在conncetion标签下,字符集要选择utf8,否则导入后的数据显示都为NULL

导入

log parser所在目录运行以下命令:

logparser.exe "SELECT * FROM 'C:inetpublogsLogFilesW3SVC5u_ex*.log'  to WebLog" 
-i:IISW3C -o:SQL -oConnString:"Dsn=iislog32" -createtable:ON

即可在mysql中查看日志数据:

2020-05-13_164810_export_mysql.png

下次导入时,去掉 -createtable:ON,会追加新的iis日志到现有数据库

注意:

  1. IIS日志在将结果导出到SQLSERVER时,字段名中不符合标识符规范的字符将会删除。
    例如:c-ip 会变成 cip, s-port 会变成 sport 。
  2. IIS日志中记录的时间是UTC时间,而且把日期和时间分开了,导出到SQLSERVER时,会生成二个字段:
    2020-05-13_165859_datasplite.png

之前是想使用链接字符串方式,一直出错,没找到原因,才选择使用ODBC!

C:Program Files (x86)Log Parser 2.2>logparser.exe "SELECT * FROM 'C:inetpublogsLogFilesW3SVC1u_ex*.log'  to WebLog" -i:IISW3C -o:SQL -oConnString:"Driver={MySQL ODBC 8.0 Unicode Driver};Server=localhost;User Id=root;Password=asdflk;Database=iislog2" -createtable:ON
Task aborted.
Error connecting to ODBC Server
  SQL State:     HY000
  Native Error:  1045
  Error Message: [MySQL][ODBC 8.0(w) Driver]Access denied for user
  'ODBC'@'localhost' (using password: YES)

Statistics:
-----------
Elements processed: 0
Elements output:    0
Execution time:     0.05 seconds

参考

原文地址:https://www.cnblogs.com/ricolee/p/iislog.html