8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 5 教程 / 5.7 将 MySQL 与 Apache 结合使用
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

5.7 在 Apache 中使用 MySQL5.7 Using MySQL with Apache

有一些程序可以让你通过 MySQL 数据库验证用户身份,同时也可以将日志文件写入 MySQL 表中。There are programs that let you authenticate your users from a MySQL database and also let you write your log files into a MySQL table.

你可以通过在 Apache 配置文件中加入以下内容来更改 Apache 日志格式,使其易于被 MySQL 读取:You can change the Apache logging format to be easily readable by MySQL by putting the following into the Apache configuration file:

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

要将该格式的日志文件加载到 MySQL 中,你可以使用类似如下的语句:To load a log file in that format into MySQL, you can use a statement something like this:

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

应创建命名表,其中的列应对应于 LogFormat 行写入日志文件的列。The named table should be created to have columns that correspond to those that the LogFormat line writes to the log file.