当前位置:网站首页>【MySQL】日志
【MySQL】日志
2022-07-06 08:20:00 【敢飞就有天空】
日志
1. 错误日志
错误日志是MySQL中最重要的日志之一,它记录了当MySQL服务启动和停止时,以及服务器在运行过程中发生任何严重错误时的相关信息。当数据库出现任何故障导致无法正常使用时,建议首先查看此日志。该日志是默认开启的,默认存放目录为 /var/log/,默认的日志文件名为 mysqld.log。
# 查看错误日志
# /var/log/mysqlld.log
show variables like '%log_error%';
2. 二进制日志
介绍
二进制日志记录了所有的 DDL语句(数据定义语言)和 DML语句(数据操纵语言),但不包括查询语句(如:SELECT、SHOW)。在MySQL8版本中,二进制日志默认是开启的,二进制日志作用如下:
- 灾难时的数据恢复
- MySQL的主从复制。
# 查看二进制日志
# /var/lib/mysql/binlog
show variables like '%log_bin%';
- log_bin_basename:当前数据库服务器的二进制日志的基础名称(前缀),具体的二进制文件名需要在该basename的基础上加上编号(编号从000001开始)。
- log_bin_index:二进制日志的索引文件,记录当前服务器关联的二进制文件。
格式
如果我们需要配置二进制日志的格式,只需要在 /etc/my.cnf 中配置 binlog_format 参数即可。
# 查看二进制日志格式
show variables like '%binlog_format%';
查看
由于日志是以二进制方式存储的,不能直接读取,需要通过二进制日志查询工具 mysqlbinlog 来查看。
删除
对于比较繁忙的业务系统,每天生成的二进制日志数据巨大,如果长时间不清除,将会占用大量磁盘空间。
# 查看二进制日志的过期时间
show variables like '%binlog_expire_logs_seconds%';
查询日志
查询日志中记录了客户端的所有操作语句,而二进制日志不包含查询数据的SQL语句。默认情况下,查询日志是未开启的。如果需要开启查询日志,可以修改MySQL的配置文件 /etc/my.cnf 文件。开启了查询日志之后,MySQL的数据存放目录,也就是 /var/lib/mysql/ 目录下就会出现 mysql_query.log 文件。之后所有的客户端的增删改查操作都会记录在该日志文件之中,长时间运行后,该日志文件将会非常大。
# 查看查询日志
show variables like '%general%';
慢查询日志
慢查询日志记录了所有执行时间超过参数 long_query_time 设置值并且扫描记录数不小于min_examined_row_limit 的所有的SQL语句的日志,默认未开启。long_query_time 默认为10 秒,最小为 0, 精度可以到微秒。
默认情况下,不会记录管理语句,也不会记录不使用索引进行查找的查询。可以使用log_slow_admin_statements和更改此行为 log_queries_not_using_indexes
上述所有的参数配置完成之后,都需要重新启动MySQL服务器才可以生效。
参考:https://www.bilibili.com/video/BV1Kr4y1i7ru
边栏推荐
- Restore backup data on S3 compatible storage with tidb lightning
- 从 SQL 文件迁移数据到 TiDB
- 1204 character deletion operation (2)
- Leetcode question brushing record | 203_ Remove linked list elements
- Go learning notes (3) basic types and statements (2)
- leetcode刷题 (5.28) 哈希表
- wincc7.5下载安装教程(Win10系统)
- vulnhub hackme: 1
- Online yaml to CSV tool
- Permutation and combination function
猜你喜欢
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
指针和数组笔试题解析
Uibehavior, a comprehensive exploration of ugui source code
Yyds dry goods inventory three JS source code interpretation eventdispatcher
How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
让学指针变得更简单(三)
leetcode刷题 (5.28) 哈希表
2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
Golang DNS write casually
Configuring OSPF load sharing for Huawei devices
随机推荐
MFC sends left click, double click, and right click messages to list controls
hcip--mpls
2022 Inner Mongolia latest construction tower crane (construction special operation) simulation examination question bank and answers
[t31zl intelligent video application processor data]
Circular reference of ES6 module
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
Upgrade tidb with tiup
CAD ARX 获取当前的视口设置
vulnhub hackme: 1
[untitled]
Restore backup data on S3 compatible storage with tidb lightning
指针和数组笔试题解析
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Huawei cloud OBS file upload and download tool class
你想知道的ArrayList知识都在这
Nacos Development Manual
Grayscale upgrade tidb operator
备份与恢复 CR 介绍
使用 BR 备份 TiDB 集群数据到兼容 S3 的存储
It's hard to find a job when the industry is in recession