MySQL数据库操作删除记录日志详解 (mysql数据库中操作删除记录日志)

MySQL是一种强大的关系型数据库管理系统,它的应用范围广泛,用于许多类型的网络应用程序,包括网站、游戏和软件应用。然而,在MySQL数据库中,删除某些记录时可能会导致数据丢失,这是每个数据库管理员必须考虑的事情。为了避免数据丢失,并提高MySQL数据库管理员的日常操作效率,本文将为您详细介绍MySQL数据库操作删除记录日志。

1. 什么是MySQL数据库操作删除记录日志

MySQL数据库删除记录日志是一种记录数据库删除操作的机制。它用于记录在任何时间点MySQL数据库中任何表中的删除操作。这是一种非常重要的机制,因为它可以用于恢复意外删除的数据。 通过使用删除记录日志,您可以确保在MySQL数据库中的数据更加安全,同时提高MySQL数据库管理员的操作效率和精度。

2. MySQL数据库操作删除记录日志的优点

MySQL数据库操作删除记录日志的一个更大的优点是,它为MySQL数据库管理员提供了一种安全保护机制。如果在MySQL数据库中误删除了某些记录,可以通过日志轻松地恢复这些记录。同时,这种机制还可以用于监视删除操作,从而更好地了解MySQL数据库中的数据操作情况。

3. 如何启用MySQL数据库操作删除记录日志

要启用MySQL数据库操作删除记录日志,您必须进行以下步骤:

3.1 修改my.cnf文件

在MySQL服务器上找到“my.cnf”文件。在打开该文件之前,首先需要备份该文件以避免任何不必要的损失。打开my.cnf文件并找到以下参数:

log-bin = /var/log/mysql/mysql-bin.log

expire_logs_days = 10

max_binlog_size = 100M

3.2 重启MySQL服务器

要使更改生效,必须重新启动MySQL服务器。要执行此操作,只需在控制台运行以下命令:

sudo service mysql restart

3.3 日志查看

要查看在MySQL数据库中执行的删除操作,只需打开MySQL控制台并执行以下命令:

mysql> show binlog events\G;

4.

MySQL数据库操作删除记录日志是一种非常实用的工具,用于记录在使用MySQL数据库时进行的删除操作。它为MySQL数据库管理员提供了安全保护机制,并可以用于恢复任何意外删除的记录。要启用MySQL数据库操作删除记录日志,只需完成几个简单的步骤。通过使用这种机制,MySQL数据库管理员可以更加合理地管理MySQL数据库,并提高操作效率和精度。

相关问题拓展阅读:

  • 为什么MySQL中删除查询日志和错误日志都是用图中红框中的那个代码,怎么区分?

为什么MySQL中删除查询日志和错误日志都是用图中红框中的那个代码,怎么区分?

flush-logs 删枣咐除磨岩棚所有的日志

flush-slow-log 删除慢查询瞎则日志

看书怎么区分,去实践,去下载mysql

MySQL 8.0 重新定义了错误日志输出和过滤,改善了原来臃肿并且可读性很差的错误日志。比如增加了 ON 输出,在原来的日志后面以序号以及 ON 后缀的方式展示。比如我机器上的 MySQL 以 ON 保存的错误日志 mysqld.log.00.json:# 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”: “T08: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”: “T08: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”: “T08:16:12.111933Z”,  “thread”旦吵: 8,  “err_symbol”: “ER_IB_MSG_391”,  “SQL_state”: “HY000”,  “label”: “Error”}以 ON 输出错误日志后可读性和可操作性增强了许多。这里可以慧哗用 Linux 命令 jq 或者把这个字串 COPY 到其他解析 ON 的工具方便处理。只想非常快速的拿出错误信息,忽略其他信息。#  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 for how to resolve the issue.””Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to for how to resolve the issue.”使用 ON 输出的前提是安装 ON 输出部件。

INSTALL COMPONENT ‘

完了在设置变量 SET GLOBAL log_error_services = ‘log_filter_internal; log_sink_json’;

格式为:过滤规则;日志输出;日志输出;查看安装好的部件mysql> select * from mysql.component;++——++| component_id | component_group_id | component_urn|++——++||    1 ||++——++3 rows in set (0.00 sec)

现在设置 ON 输出,输出到系统日志的同时输出到 ON 格式日志。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 条记录。

# tailf  mysqld.log

T08:16:12.111808Z 8 Operating system error number 2 in a file operation.

T08:16:12.111915Z 8 The error means the system cannot find the path specified.

T08:16:12.111933Z 8 Cannot open datafile for read-only: ‘./ytt2/a.ibd’ OS error: 71

T08:16:12.112227Z 8 Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to for how to resolve the issue.

T08:16:14.902617Z 8 Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to for how to resolve the issue.

ON 日志里也有 5 条记录。

# 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” : “T08: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” : “T08: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” : “T08:16:12.111933Z”, “thread” : 8, “err_symbol” : “ER_IB_MSG_391”, “SQL_state” : “HY000”, “label” : “Error” }

{ “log_type” : 1, “prio” : 2, “err_code” : 12023, “subsystem” : “InnoDB”, “msg” : “Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to for how to resolve the issue.”, “time” : “T08:16:12.112227Z”, “thread” : 8, “err_symbol” : “ER_IB_MSG_224”, “SQL_state” : “HY000”, “label” : “Warning” }

{ “log_type” : 1, “prio” : 2, “err_code” : 12023, “subsystem” : “InnoDB”, “msg” : “Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to for how to resolve the issue.”, “time” : “T08:16:14.902617Z”, “thread” : 8, “err_symbol” : “ER_IB_MSG_224”, “SQL_state” : “HY000”, “label” : “Warning” }

那可能有人就问了,这有啥意义呢?只是把格式变了,过滤的规则我看还是没变。那我们现在给第二条日志输出加过滤规则先把过滤日志的部件安装起来

INSTALL COMPONENT ‘

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`.

查看错误日志和 ON 错误日志发现错误日志里有一条 Warning,ON 错误日志里的被过滤掉了。T08:22:32.978728Z 8 Cannot calculate statistics for table `ytt2`.`a` because the .ibd file is missing. Please refer to 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 信息

T08:49:06.820235Z 8 Cannot calculate statistics for table `ytt2`.`b` because the .ibd file is missing. Please refer to for how to resolve the issue.

T08:49:31.455907Z 8 Cannot calculate statistics for table `ytt2`.`b` because the .ibd file is missing. Please refer to for how to resolve the issue.

T08:50:00.430867Z 8 Cannot calculate statistics for table `ytt2`.`b` because the .ibd file is missing. Please refer to for how to resolve the issue.

mysqld.log.00.json 只有一条{ “log_type” : 1, “prio” : 2, “err_code” : 12023, “subsystem” : “InnoDB”, “msg” : “Cannot calculate statistics for table `ytt2`.`b` because the .ibd file is missing. Please refer to for how to resolve the issue.”, “time” : “T08:49:06.820235Z”, “thread” : 8, “err_symbol” : “ER_IB_MSG_224”, “SQL_state” : “HY000”, “and_n_more” : 3, “label” : “Warning” }

总结,我这里简单介绍了下 MySQL 8.0 的错误日志过滤以及 ON 输出。MySQL 8.0 的component_log_filter_dragnet 部件过滤规则非常灵活,可以参考手册,根据它提供的语法写出自己的过滤掉的日志输出。

关于mysql数据库中操作删除记录日志的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

香港服务器首选树叶云,2H2G首月10元开通。
树叶云(www.IDC.Net)提供简单好用,价格厚道的香港/美国云服务器和独立服务器。IDC+ISP+ICP资质。ARIN和APNIC会员。成熟技术团队15年行业经验。

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/293464.html<

(0)
管理的头像管理
上一篇2025-05-20 15:16
下一篇 2025-05-20 15:17

相关推荐

  • jsp空间购买和交换数据空间怎么买,有哪些注意事项?

    购买JSP空间时,是否考虑过数据交换空间的性能?简米科技(2003年始创,23年行业沉淀)与酷番云(工信部一类增值电信全牌照)这类持牌自营机房的服务商,能确保数据交换的高效稳定,是值得优先选择的合作伙伴,为什么JSP空间需要搭配独立的数据交换空间从JSP应用特性看数据交换需求JSP基于Java技术,常用于企业级……

    2026-08-11
    0
  • 建网站用香港空间效果怎么样,香港空间稳定吗?

    建网站用香港空间,对于创建网站资产来说,核心价值在于免备案和全球带宽优势,尤其适合外贸、跨境电商和需要快速启动的项目,但你必须权衡国内访问延迟,并选择有资质的服务商以保证资产安全,香港空间的核心优势与适用边界免备案:节省时间就是节省成本国内服务器需要备案,通常需要10到20天,香港空间无需备案,域名解析后即可上……

    2026-08-11
    0
  • Java连接云数据库的方法是什么,如何操作

    Java连接云数据库的核心在于通过JDBC驱动,结合云服务商提供的连接地址、端口、数据库名及认证信息,配置安全策略(如SSL、IP白名单),即可实现稳定高效的远程数据库访问,基础准备:JDBC驱动与依赖管理连接云数据库前,需要确保开发环境具备对应的JDBC驱动,以最常见的MySQL为例,你需要引入mysql-c……

    2026-08-11
    0
  • 建网站公安联网备案必须使用数据码吗,备案流程是什么

    网站备案包括ICP备案和公安联网备案,两者缺一不可,公安联网备案必须使用服务商提供的数据码,选择持有合法资质的服务商是顺利通过备案的前提,为什么网站必须进行公安联网备案根据公安部《计算机信息网络国际联网安全保护管理办法》,网站开通后30日内必须到公安机关办理备案手续,未完成公安备案的网站,面临责令整改、关闭网站……

    2026-08-10
    0
  • 建一个企业网站大概需要多少钱?,怎么收费?

    建网站要多少钱,没有一个固定的数字,几百到几万都可能,但真正的“创建网站资产”绝不仅仅是初次投入的成本,而是基于长期稳定、合规和安全的持续性投入,其中核心取决于你选择了什么样的“地基”来承载你的业务,建站预算的构成与行业基准当你开始规划一个网站,最先面对的就是预算问题,一个常见的误区是只关注网站“看起来”的建造……

    2026-08-10
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注