当前位置:网站首页>【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
边栏推荐
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- JS select all and tab bar switching, simple comments
- 2. File operation - write
- Tidb backup and recovery introduction
- ESP系列引脚說明圖匯總
- [research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached
- Common functions for PHP to process strings
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- logback1.3. X configuration details and Practice
- CAD ARX 获取当前的视口设置
猜你喜欢

Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation

Database basic commands

Wincc7.5 download and installation tutorial (win10 system)
![[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]](/img/ae/4e616882f6d68acdf8e885843e68a3.jpg)
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]

IoT -- 解读物联网四层架构

synchronized 解决共享带来的问题
![[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached](/img/35/898a8086bc35462b0fcb9e6b58b86b.jpg)
[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached

"Designer universe" Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers | national economic and Informa
![[research materials] 2021 Research Report on China's smart medical industry - Download attached](/img/c8/a205ddc2835c87efa38808cf31f59e.jpg)
[research materials] 2021 Research Report on China's smart medical industry - Download attached

Asia Pacific Financial Media | "APEC industry +" Western Silicon Valley invests 2trillion yuan in Chengdu Chongqing economic circle to catch up with Shanghai | stable strategy industry fund observatio
随机推荐
Asia Pacific Financial Media | "APEC industry +" Western Silicon Valley invests 2trillion yuan in Chengdu Chongqing economic circle to catch up with Shanghai | stable strategy industry fund observatio
指针和数组笔试题解析
从 TiDB 集群迁移数据至另一 TiDB 集群
Circuit breaker: use of hystrix
Secure captcha (unsafe verification code) of DVWA range
使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
C language custom type: struct
ESP series pin description diagram summary
Vocabulary notes for postgraduate entrance examination (3)
LDAP应用篇(4)Jenkins接入
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Leetcode question brushing record | 203_ Remove linked list elements
[Yugong series] creation of 009 unity object of U3D full stack class in February 2022
Entity class design for calculating age based on birthday
All the ArrayList knowledge you want to know is here
将 NFT 设置为 ENS 个人资料头像的分步指南
CAD ARX 获取当前的视口设置
C语言 - 位段
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?