新特性解读 | MySQL 8.0 错误日志增强特性
编程并不是一个机械性的工作,而是需要有思考,有创新的工作,语法是固定的,但解决问题的思路则是依靠人的思维,这就需要我们坚持学习和更新自己的知识。今天golang学习网就整理分享《新特性解读 | MySQL 8.0 错误日志增强特性》,文章讲解的知识点主要包括MySQL、数据库,如果你对数据库方面的知识点感兴趣,就不要错过golang学习网,在这可以对大家的知识积累有所帮助,助力开发能力的提升。
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 https://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 https://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 https://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 https://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 https://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 https://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 https://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 https://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 https://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 https://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 https://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 部件过滤规则非常灵活,可以参考手册,根据它提供的语法写出自己的过滤掉的日志输出。
以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于数据库的相关知识,也可关注golang学习网公众号。
-
- 数据库 · MySQL | 1天前 |
- MySQL数值函数大全及使用技巧
- 117浏览 收藏
-
- 数据库 · MySQL | 3天前 |
- 三种登录MySQL方法详解
- 411浏览 收藏
-
- 数据库 · MySQL | 4天前 |
- MySQL数据备份方法与工具推荐
- 420浏览 收藏
-
- 数据库 · MySQL | 4天前 |
- MySQL数据备份方法与工具推荐
- 264浏览 收藏
-
- 数据库 · MySQL | 5天前 |
- MySQL索引的作用是什么?
- 266浏览 收藏
-
- 数据库 · MySQL | 6天前 |
- MySQL排序原理与实战应用
- 392浏览 收藏
-
- 数据库 · MySQL | 1星期前 |
- MySQLwhere条件查询技巧
- 333浏览 收藏
-
- 数据库 · MySQL | 1星期前 |
- MySQL常用数据类型有哪些?怎么选更合适?
- 234浏览 收藏
-
- 数据库 · MySQL | 1星期前 |
- MySQL常用命令大全管理员必学30条
- 448浏览 收藏
-
- 数据库 · MySQL | 1星期前 |
- MySQL高效批量插入数据方法大全
- 416浏览 收藏
-
- 数据库 · MySQL | 1星期前 |
- MySQL性能优化技巧大全
- 225浏览 收藏
-
- 数据库 · MySQL | 1星期前 |
- MySQL数据备份4种方法保障安全
- 145浏览 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 485次学习
-
- ChatExcel酷表
- ChatExcel酷表是由北京大学团队打造的Excel聊天机器人,用自然语言操控表格,简化数据处理,告别繁琐操作,提升工作效率!适用于学生、上班族及政府人员。
- 3179次使用
-
- Any绘本
- 探索Any绘本(anypicturebook.com/zh),一款开源免费的AI绘本创作工具,基于Google Gemini与Flux AI模型,让您轻松创作个性化绘本。适用于家庭、教育、创作等多种场景,零门槛,高自由度,技术透明,本地可控。
- 3390次使用
-
- 可赞AI
- 可赞AI,AI驱动的办公可视化智能工具,助您轻松实现文本与可视化元素高效转化。无论是智能文档生成、多格式文本解析,还是一键生成专业图表、脑图、知识卡片,可赞AI都能让信息处理更清晰高效。覆盖数据汇报、会议纪要、内容营销等全场景,大幅提升办公效率,降低专业门槛,是您提升工作效率的得力助手。
- 3419次使用
-
- 星月写作
- 星月写作是国内首款聚焦中文网络小说创作的AI辅助工具,解决网文作者从构思到变现的全流程痛点。AI扫榜、专属模板、全链路适配,助力新人快速上手,资深作者效率倍增。
- 4525次使用
-
- MagicLight
- MagicLight.ai是全球首款叙事驱动型AI动画视频创作平台,专注于解决从故事想法到完整动画的全流程痛点。它通过自研AI模型,保障角色、风格、场景高度一致性,让零动画经验者也能高效产出专业级叙事内容。广泛适用于独立创作者、动画工作室、教育机构及企业营销,助您轻松实现创意落地与商业化。
- 3799次使用
-
- golang MySQL实现对数据库表存储获取操作示例
- 2022-12-22 499浏览
-
- 搞一个自娱自乐的博客(二) 架构搭建
- 2023-02-16 244浏览
-
- B-Tree、B+Tree以及B-link Tree
- 2023-01-19 235浏览
-
- mysql面试题
- 2023-01-17 157浏览
-
- MySQL数据表简单查询
- 2023-01-10 101浏览

mysql时间筛选
