mysql insert 不需要日志_详解MySQL|你不知道的新特性-8.0错误日志增强

5087c751afbb4bae3580bf64fca0849c.png

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.log2019-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: 712019-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 部件过滤规则非常灵活,可以参考手册,根据它提供的语法写出自己的过滤掉的日志输出。

e3c4922b8df7608940ee7a36817db2e1.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/431314.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

idea中java文件怎么运行_Java入门基础篇-如何在Java中创建只读文件

本文选自千锋教育《Java语言程序设计》,如需转载请注明出处,谢谢!1、如何创建只读文件要使文件只读,我们只要将文件属性更改为只读就行;可以使用File类的setReadOnly()方法来实现。它会返回一个布尔值,这样…

模仿JavaAppArguments.java示例

要求:编写一个程序,此程序从命令行接受多个数字,求和之后输出结果。 设计思想:命令行的参数都是字符串,需要定义一个整形数组将其转化为整数,然后实现数字的相加,最后输出结果。 程序流程图&…

showdoc windows 搭建_ShowDoc的搭建

其实,官方文档也说的很清楚了。主要贴一下我遇见的问题。环境:LNMP(LAMP没试过,有兴趣的同学可以试试,然后发出来)PHP5.3以上版本、php-mbstring模块、php-pdo模块、mysql数据库克隆或者下载代码:https://github.com/s…

2020年408真题_自考书院:2020年10月00830现代语言学真题

免费发布2020年10月全国统一命题《00830现代语言学》试卷其他真题:甘肃自考网 >> 历年试题 >>http://www.gseea.net点击历年真题查看更多真题和复习资料【互动交流平台】:交流QQ一群:35167222交流QQ二群:251822544自考…

linux优先级队列,Python3 线程优先级队列( Queue)

导读Python 的 Queue 模块中提供了同步的、线程安全的队列类,包括FIFO(先入先出)队列Queue,LIFO(后入先出)队列LifoQueue,和优先级队列 PriorityQueue。这些队列都实现了锁原语,能够在多线程中直接使用,可以使用队列来…

泛泰A860(高通公司8064 cpu 1080p) 拂4.4中国民营recovery TWRP2.7.1.2文本(通过刷第三版)...

专业第三方开发团队 VegaDevTeam (本team 由 syhost suky zhaochengw(z大) xuefy(大星星) tenfar(R大师) loogeo crazyi(天下无雪) windxixi(雪狐) wangsai008 组成) 说说中文TWRP的简史: 中文TWRP是本人在2012.10月在原英文TWRP的基础上首次改…

linux重启memcache_Linux下的Memcache安装方法

Linux下Memcache服务器端的安装服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.3.0 。下载:http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz另外,Memcache用到了libevent这个库用于Socket的处理,…

电脑机箱cad图纸_如何批量打印高清黑白CAD图纸?这么好用的方法现在才知道

工作中为了更方便查看和传阅CAD图纸,经常要将CAD图纸打印出来,有时候要打印很多张,而且还不是最终定稿!如果打印成彩印也太浪费墨水了!所以批量打印黑白图纸的技巧就显得十分重要啦!很多小伙伴们都不知道怎…

c语言链表编程作业,C语言编程入门——链表

链表是为克服数组的缺点,在内存空间中离散存储,但需要一个指针记住下一个结点的地址,以便可以将链表结点连接起来。链表与数组的比较:数组优点:存取速度快。缺点:插入和删除元素的效率很低;需要…

Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP

D. Painting The WallUser ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n  n table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the rules below. Firstly user a…

ahp层次分析法_基于层次分析法(AHP)的店铺选址应用研究

导读在连锁行业,店铺选址是其中很重要的一个方面。影响店铺选址的指标(因素)很多,决策中经常需要对店铺影响各指标进行量化分析。本文应用层级分析法(AHP),对影响店铺选址的指标(因素)权重进行量化分析,以帮助决策者从备选的多个店…

html页面刷新回到顶部_页面刷新后,使页面自动滚回到顶部

比如有一个页面,滚动条在body上,当页面滚动到下方时,如何在刷新后使页面滚动回初始位置?已尝试但是失效的方案:$("body").scrollTop(0);window.scrollTo(0,0);document.body.scrollTop0;除了页面跳转&#x…

当c语言表达式中同时有字符 整数,c语言第2章数据类型、运算符与表达式a.ppt

c语言第2章数据类型、运算符与表达式aC语言程序设计;本章主要学习任务;2.1 C的数据类型;注意:C语言中的数据有变量与常量,它们分别属于上述这些类型。;2.2 常量与变量;不是C语句,不必在行末加分号。该命令是用标识符代替一个字符串&#xff0…

构造函数和clone以及在继承中

构造函数 类实例的构造创建过程是: 1.属性域被初始化为默认值(0,false,null) 2.按照在类声明的顺序初始化初始化语句和初始化块. 3.执行构造函数 所以,一个默认的空的无参构造函数并没有初始化类的实例域.因为实例域先于构造而初始化完毕了.构造函数无法被继承如果一个类没有定…

python批量删缩进_鬼畜小姐姐+野狼disco,十分钟教你如何用Python剪辑一个牛逼的抖音小视频?...

鬼畜小姐姐野狼disco,十分钟教你如何用Python剪辑一个牛逼的抖音小视频?前言半个月前,后台有个小伙伴问我,如何将视频中的音频提取出来,并且将声音转成文字写入到 word 中,正好接下来的文章要用到百度的语音…

web无序列表去掉点_无序列表排序之方法

利用jQuery对无序列表排序的原理是:获取到无序列表中的所有列表项,并转成数组形式,使用JavaScript函数对其进行排序后再次输出。其中使用到的jQuery函数有ready()、get()、text()、each()、append()和JavaScript函数sort()。1.jQu…

c语言编程怎么实现替换,使用C语言实现字符串中子字符串的替换

描述:编写一个字符串替换函数,如函数名为 StrReplace(char* strSrc, char* strFind, char* strReplace),strSrc为原字符串,strFind是待替换的字符串,strReplace为替换字符串。举个直观的例子吧,如&#xff…

数据结构:点之间的最短距离--Floyd算法

Floyd算法 Floyd算法 Dijkstra算法是用于解决单源最短路径问题的,Floyd算法则是解决点对之间最短路径问题的。Floyd算法的设计策略是动态规划,而Dijkstra採取的是贪心策略。当然,贪心算法就是动态规划的特例。 算法思想 点对之间的最短路径仅…

shell 获取家目录_一篇教会你写90%的shell脚本

shell是外壳的意思,就是操作系统的外壳。我们可以通过shell命令来操作和控制操作系统,比如Linux中的Shell命令就包括ls、cd、pwd等等。总结来说,Shell是一个命令解释器,它通过接受用户输入的Shell命令来启动、暂停、停止程序的运行…

数据结构c语言版第四章题库,数据结构(C语言版)(第4版)习题

数据结构(C语言版)(第4版)习题 习题 11.1 选择题。(1)计算机识别、存储和加工处理的对象统称为 。A.数据 B.数据元素 C.数据结构 D.数据类型(2)数据结构通常是研究数据的 及它们之间的联系。A.存储和逻辑结构 B.存储和抽象 C.理想和抽象 D.理想和逻辑(3)…