mysql错误日志在哪里
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql错误日志在哪里相关的知识,希望对你有一定的参考价值。
如果你什么都没改过,如果是windows下,一般是安装目录下的data目录下 扩展名是.err那个文件,你可以打开安装目录下的my.ini文件检查一下
如果是linux下,一般是/var/log/mysqld.log,你最好用cat /etc/my.cnf看看 参考技术A
MySQL 8.0 重新定义了错误日志输出和过滤,改善了原来臃肿并且可读性很差的错误日志。比如增加了 JSON 输出,在原来的日志后面以序号以及 JSON 后缀的方式展示。比如我机器上的 MySQL 以 JSON 保存的错误日志 mysqld.log.00.json:[root@centos-ytt80 mysql80]# jq . mysqld.log.00.json "log_type": 1, "prio": 1, "err_code": 12592, "subsystem": "InnoDB", "msg": "Operating system error number 2 in a file operation.", "time": "2019-09-03T08:16:12.111808Z", "thread": 8, "err_symbol": "ER_IB_MSG_767", "SQL_state": "HY000", "label": "Error" "log_type": 1, "prio": 1, "err_code": 12593, "subsystem": "InnoDB", "msg": "The error means the system cannot find the path specified.", "time": "2019-09-03T08:16:12.111915Z", "thread": 8, "err_symbol": "ER_IB_MSG_768", "SQL_state": "HY000", "label": "Error" "log_type": 1, "prio": 1, "err_code": 12216, "subsystem": "InnoDB", "msg": "Cannot open datafile for read-only: './ytt2/a.ibd' OS error: 71", "time": "2019-09-03T08:16:12.111933Z", "thread": 8, "err_symbol": "ER_IB_MSG_391", "SQL_state": "HY000", "label": "Error"以 JSON 输出错误日志后可读性和可操作性增强了许多。这里可以用 Linux 命令 jq 或者把这个字串 COPY 到其他解析 JSON 的工具方便处理。只想非常快速的拿出错误信息,忽略其他信息。[root@centos-ytt80 mysql80]# jq '.msg' mysqld.log.00.json"Operating system error number 2 in a file operation.""The error means the system cannot find the path specified.""Cannot open datafile for read-only: './ytt2/a.ibd' OS error: 71""Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.""Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue."使用 JSON 输出的前提是安装 JSON 输出部件。
INSTALL COMPONENT 'file://component_log_sink_json';
完了在设置变量 SET GLOBAL log_error_services = 'log_filter_internal; log_sink_json';
格式为:过滤规则;日志输出;[过滤规则]日志输出;查看安装好的部件mysql> select * from mysql.component;+--------------+--------------------+---------------------------------------+| component_id | component_group_id | component_urn |+--------------+--------------------+---------------------------------------+| 2 | 1 | file://component_log_sink_json |+--------------+--------------------+---------------------------------------+3 rows in set (0.00 sec)
现在设置 JSON 输出,输出到系统日志的同时输出到 JSON 格式日志。mysql> SET persist log_error_services = 'log_filter_internal; log_sink_internal; log_sink_json';Query OK, 0 rows affected (0.00 sec)
来测试一把。我之前已经把表 a 物理文件删掉了。mysql> select * from a;ERROR 1812 (HY000): Tablespace is missing for table `ytt2`.`a`.
现在错误日志里有 5 条记录。
[root@centos-ytt80 mysql80]# tailf mysqld.log
2019-09-03T08:16:12.111808Z 8 [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
2019-09-03T08:16:12.111915Z 8 [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
2019-09-03T08:16:12.111933Z 8 [ERROR] [MY-012216] [InnoDB] Cannot open datafile for read-only: './ytt2/a.ibd' OS error: 71
2019-09-03T08:16:12.112227Z 8 [Warning] [MY-012049] [InnoDB] Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.
2019-09-03T08:16:14.902617Z 8 [Warning] [MY-012049] [InnoDB] Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.
JSON 日志里也有 5 条记录。
[root@centos-ytt80 mysql80]# tailf mysqld.log.00.json
"log_type" : 1, "prio" : 1, "err_code" : 12592, "subsystem" : "InnoDB", "msg" : "Operating system error number 2 in a file operation.", "time" : "2019-09-03T08:16:12.111808Z", "thread" : 8, "err_symbol" : "ER_IB_MSG_767", "SQL_state" : "HY000", "label" : "Error"
"log_type" : 1, "prio" : 1, "err_code" : 12593, "subsystem" : "InnoDB", "msg" : "The error means the system cannot find the path specified.", "time" : "2019-09-03T08:16:12.111915Z", "thread" : 8, "err_symbol" : "ER_IB_MSG_768", "SQL_state" : "HY000", "label" : "Error"
"log_type" : 1, "prio" : 1, "err_code" : 12216, "subsystem" : "InnoDB", "msg" : "Cannot open datafile for read-only: './ytt2/a.ibd' OS error: 71", "time" : "2019-09-03T08:16:12.111933Z", "thread" : 8, "err_symbol" : "ER_IB_MSG_391", "SQL_state" : "HY000", "label" : "Error"
"log_type" : 1, "prio" : 2, "err_code" : 12049, "subsystem" : "InnoDB", "msg" : "Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.", "time" : "2019-09-03T08:16:12.112227Z", "thread" : 8, "err_symbol" : "ER_IB_MSG_224", "SQL_state" : "HY000", "label" : "Warning"
"log_type" : 1, "prio" : 2, "err_code" : 12049, "subsystem" : "InnoDB", "msg" : "Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.", "time" : "2019-09-03T08:16:14.902617Z", "thread" : 8, "err_symbol" : "ER_IB_MSG_224", "SQL_state" : "HY000", "label" : "Warning"
那可能有人就问了,这有啥意义呢?只是把格式变了,过滤的规则我看还是没变。那我们现在给第二条日志输出加过滤规则先把过滤日志的部件安装起来
INSTALL COMPONENT 'file://component_log_filter_dragnet';
mysql> SET persist log_error_services = 'log_filter_internal; log_sink_internal; log_filter_dragnet;log_sink_json';
Query OK, 0 rows affected (0.00 sec)
只保留 error,其余的一律过滤掉。SET GLOBAL dragnet.log_error_filter_rules = 'IF prio>=WARNING THEN drop.';
检索一张误删的表mysql> select * from a;ERROR 1812 (HY000): Tablespace is missing for table `ytt2`.`a`.
查看错误日志和 JSON 错误日志发现错误日志里有一条 Warning,JSON 错误日志里的被过滤掉了。2019-09-03T08:22:32.978728Z 8 [Warning] [MY-012049] [InnoDB] Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.
再举个例子,每 60 秒只允许记录一个 Warning 事件mysql> SET GLOBAL dragnet.log_error_filter_rules = 'IF prio==WARNING THEN throttle 1/60.';Query OK, 0 rows affected (0.00 sec)
多次执行mysql> select * from b;ERROR 1812 (HY000): Tablespace is missing for table `ytt2`.`b`.mysql> select * from b;ERROR 1812 (HY000): Tablespace is missing for table `ytt2`.`b`.mysql> select * from b;ERROR 1812 (HY000): Tablespace is missing for table `ytt2`.`b`.
现在错误日志里有三条 warning 信息
2019-09-03T08:49:06.820635Z 8 [Warning] [MY-012049] [InnoDB] Cannot calculate statistics for table `ytt2`.`b` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.
2019-09-03T08:49:31.455907Z 8 [Warning] [MY-012049] [InnoDB] Cannot calculate statistics for table `ytt2`.`b` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.
2019-09-03T08:50:00.430867Z 8 [Warning] [MY-012049] [InnoDB] Cannot calculate statistics for table `ytt2`.`b` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.
mysqld.log.00.json 只有一条 "log_type" : 1, "prio" : 2, "err_code" : 12049, "subsystem" : "InnoDB", "msg" : "Cannot calculate statistics for table `ytt2`.`b` because the .ibd file is missing. Please refer to http://dev.mysql.com/doc/refman/8.0/en/innodb-troubleshooting.html for how to resolve the issue.", "time" : "2019-09-03T08:49:06.820635Z", "thread" : 8, "err_symbol" : "ER_IB_MSG_224", "SQL_state" : "HY000", "and_n_more" : 3, "label" : "Warning"
总结,我这里简单介绍了下 MySQL 8.0 的错误日志过滤以及 JSON 输出。MySQL 8.0 的component_log_filter_dragnet 部件过滤规则非常灵活,可以参考手册,根据它提供的语法写出自己的过滤掉的日志输出。
我在哪里可以找到 phpMyAdmin 中的 MySQL 日志?
【中文标题】我在哪里可以找到 phpMyAdmin 中的 MySQL 日志?【英文标题】:Where can I find MySQL logs in phpMyAdmin? 【发布时间】:2011-03-03 15:49:43 【问题描述】:在 phpMyAdmin 界面哪里可以找到 MySQL 的日志(错误、查询等)?
【问题讨论】:
【参考方案1】:在 phpMyAdmin 4.0 中,您转到状态 > 监控。在那里您可以启用慢查询日志和一般日志,查看实时监视器,选择图表的一部分,查看相关查询并分析它们。
【讨论】:
【参考方案2】:使用 performance_schema 数据库和表格:
-
events_statements_current
events_statemenets_history
events_statemenets_history_long
查看手册here
【讨论】:
【参考方案3】:我遇到了@rutherford 的同样问题,今天新的 phpMyAdmin 的 3.4.11.1 GUI 有所不同,所以我想如果有人用更新的信息改进答案会更好。
完整的mysql日志可以在:
“状态”->“二进制日志”
这就是答案,不管你使用的是 MAMP、XAMPP、LAMP 等。
【讨论】:
【参考方案4】:打开您的 PHPMyAdmin,不要选择任何数据库并查找 Binary Log
选项卡。
您可以从下拉列表中选择不同的日志,然后按GO
按钮查看它们。
【讨论】:
我有数据库、SQL、状态、变量、字符集、引擎、进程、导出和导入选项卡,但没有“二进制日志” - 我是否在正确的位置查找? 嗯,我在引擎和进程之间有权限和二进制日志。你在使用 WAMP 吗?哪个版本?你是用root登录的吗? 啊,那可能是被我的主机限制了。我会问他们,谢谢你的帮助。 我找不到Binary Log tab
!也没有任何与日志相关的标签!
@MuhammadGelbana,它位于“状态”选项卡下。如果您单击它,然后查看“服务器流量”上方的列表项,您将看到“线程”和“临时数据”之间的“二进制日志”。【参考方案5】:
我正在使用 phpMyAdmin 版本 4.2.11。在撰写本文时,我的Status
标签看起来像这样(扩展了一些选项;注意“当前设置”,右下角):
请注意,没有直接可见的“功能”允许启用诸如slow_query_log
之类的东西。因此,我在互联网上进行了挖掘,因为面向 UI 的答案仅与特定版本相关,因此很快就会过时。那么,如果您没有在上面看到相关答案,您会怎么做?
作为article explains,您可以运行全局查询来启用或禁用slow_query_log
等。 启用和禁用这些日志的查询并不难,所以不要害怕它们,例如
SET GLOBAL slow_query_log = 'ON';
从这里开始,phpMyAdmin 非常有帮助,一点点谷歌搜索可以让您立即上手。例如,在运行上述查询后,我可以返回状态选项卡的Monitor
窗口下的“说明/设置”选项并查看以下内容(请注意进一步的说明):
【讨论】:
这个答案看起来不错,因为这正是我的情况。不幸的是,它并不总是有效,因为您需要 SUPER 权限:“错误 SQL 查询:SET GLOBAL slow_query_log = 'ON' #1227 - 访问被拒绝;您需要(至少一个)该操作的 SUPER 权限” 【参考方案6】:如果您使用 XAMPP 作为服务器,您会发现日志目录是 XAMPP 目录的子目录。如果您还没有尝试过 XAMPP,它可以在任何系统(Windows、Mac OS 和 Linux)上运行,请在此处找到更多信息:http://www.apachefriends.org/en/xampp.html
【讨论】:
以上是关于mysql错误日志在哪里的主要内容,如果未能解决你的问题,请参考以下文章