文章目录
- MySQL 8.0 架构 之错误日志文件(Error Log)(1)
- MySQL错误日志文件(Error Log)
- MySQL错误日志在哪里
- Window环境
- Linux环境
- 错误日志相关参数
- log_error_services
- 参考
【声明】文章仅供学习交流,观点代表个人,与任何公司无关。
编辑|SQL和数据库技术(ID:SQLplusDB)
MySQL 8.0 OCP (1Z0-908) 考点概要
MySQL 8.0 OCP (1Z0-908) 考点精析-安装与配置考点1:设置系统变量
【MySQL】控制MySQL优化器行为方法之optimizer_switch系统变量
【MySQL】MySQL系统变量(system variables)列表(mysqld –verbose –help的结果例)
【MySQL】MySQL系统变量(system variables)列表(SHOW VARIABLES 的结果例)
MySQL 8.0 OCP (1Z0-908) 考点精析-备份与恢复考点1:MySQL Enterprise Backup概要
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点1:sys.statement_analysis视图
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点2:系统变量的确认
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点3:EXPLAIN ANALYZE
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点4:慢速查询日志(slow query log)
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点5:表连接算法(join algorithm)
MySQL 8.0 OCP (1Z0-908) 考点精析-性能优化考点6:MySQL Enterprise Monitor之Query Analyzer
MySQL 8.0 OCP (1Z0-908) 考点精析-架构考点1:二进制日志文件(Binary log)
MySQL 8.0 OCP (1Z0-908) 考点精析-架构考点5:数据字典(Data Dictionary)
MySQL 8.0 OCP (1Z0-908) 考点精析-架构考点6:InnoDB Tablespaces之系统表空间(System Tablespace)
MySQL 8.0 InnoDB Tablespaces之File-per-table tablespaces(单独表空间)
MySQL 8.0 InnoDB Tablespaces之General Tablespaces(通用表空间/一般表空间)
【MySQL】在数据目录之外创建InnoDB 表(Creating Tables Externally)
MySQL 8.0 InnoDB Tablespaces之Temporary Tablespaces(临时表空间)
MySQL 8.0 InnoDB 架构之 日志缓冲区(Log Buffer)和重做日志(Redo Log)
MySQL 8.0 架构 之错误日志文件(Error Log)(1)
MySQL 8.0 架构 之错误日志文件(Error Log)(1)
MySQL中有多种类型的日志文件,这些日志可用于故障排除、性能调整和审计等目的,帮助找出正在发生的活动。
常见的日志文件包括:
日志类型 | 写入日志的信息 |
---|---|
错误日志(Error log) | 启动、运行或停止mysqld时遇到的问题 |
二进制日志(Binary log) | 更改数据的语句(也用于复制) |
中继日志(Relay log) | 从复制源服务器接收到的数据更改 |
通用查询日志(General query log) | 已建立的客户端连接和从客户端接收到的语句 |
慢查询日志(Slow query log) | 执行时间超过long_query_time秒的查询 |
DDL日志(元数据日志)(DDL log) | DDL语句执行的元数据操作 |
MySQL错误日志文件(Error Log)
错误日志(Error Log)主要用于记录 MySQL 服务器启动和停止过程中的信息、以及服务器在运行过程中发生的故障和异常情况等信息。另外,错误日志功能默认为开启状态。
MySQL错误日志在哪里
通过log_error参数可以查看错误日志的路径和文件名。
- 方法1:在MySQL的配置文件(my.cnf或my.ini)中,搜索log_error参数
- 方法2:通过MySQL的SHOW 命令命令查看log_error参数
log_error参数:
Command-Line Format | –log-error[=file_name] |
---|---|
System Variable | log_error |
Scope | Global |
Dynamic | No |
SET_VAR Hint Applies | No |
Type | File name |
参考:
log_error
https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_log_error
Window环境
在Window环境中,错误日志默认存储在 MySQL 数据库的数据文件夹下,通常名称为 hostname.err。
其中,hostname 表示 MySQL 服务器的主机名。
例:
mysql> show variables like 'log_error';+---------------+-----------------------+| Variable_name | Value |+---------------+-----------------------+| log_error | .\PC-202106271542.err |+---------------+-----------------------+1 row in set, 1 warning (0.11 sec)mysql> show variables like 'datadir';+---------------+-----------------------------+| Variable_name | Value |+---------------+-----------------------------+| datadir | E:\Soft\MySQL8.0\data\Data\ |+---------------+-----------------------------+1 row in set, 1 warning (0.00 sec)mysql>
通过上面的内容可以看到错误日志为E:\Soft\MySQL8.0\data\Data\PC-202106271542.err。
错误日志以文本文件的形式存储,可以通过普通文本工具查看。
错误日志输出例:
2024-01-13T22:40:14.008389Z 0 [System] [MY-010116] [Server] E:\Soft\MySQL8.0\bin\mysqld.exe (mysqld 8.0.28) starting as process 24362024-01-13T22:40:16.764578Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.2024-01-13T22:40:22.142343Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.2024-01-13T22:40:26.603871Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.2024-01-13T22:40:26.605011Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.2024-01-13T22:40:28.060801Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 330602024-01-13T22:40:28.061433Z 0 [System] [MY-010931] [Server] E:\Soft\MySQL8.0\bin\mysqld.exe: ready for connections. Version: '8.0.28'socket: ''port: 3306MySQL Community Server - GPL.
Linux环境
在Linux环境中,错误日志默认存储在 /var/log/mysql/文件夹下,通常名称为error.log 。
例:
mysql> show variables like 'log_error';+---------------+--------------------------+| Variable_name | Value|+---------------+--------------------------+| log_error | /var/log/mysql/error.log |+---------------+--------------------------+1 row in set (0.00 sec)
文件如下:
root@mysql-vm:/var/log/mysql# ls -ltotal 32-rw-r----- 1 mysql adm446 Dec 30 06:49 error.log-rw-r----- 1 mysql adm297 Dec 29 23:20 error.log.1.gz-rw-r----- 1 mysql adm 1844 Dec 28 20:55 error.log.2.gz-rw-r----- 1 mysql adm 20 Dec 27 21:19 error.log.3.gz-rw-r----- 1 mysql adm 20 Dec 26 21:04 error.log.4.gz-rw-r----- 1 mysql adm 1165 Dec 24 22:11 error.log.5.gz-rw-r----- 1 mysql adm389 Dec 23 09:07 error.log.6.gz-rw-r----- 1 mysql adm248 Dec 20 20:29 error.log.7.gzroot@mysql-vm:/var/log/mysql#
可以通过cat、more等linux命令查看错误日志文件。
例:
root@mysql-vm:/var/log/mysql# more error.log2023-12-29T17:31:18.719726Z 23 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'2023-12-29T22:49:18.399315Z 24 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'root@mysql-vm:/var/log/mysql#
对于gz的备份文件,可以通过zcat 命令查看。
例:
root@mysql-vm:/var/log/mysql# zcat error.log.5.gz |more2023-12-24T13:54:59.579065Z 28 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'2023-12-24T14:00:25.985956Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.35-0ubuntu0.22.04.1).2023-12-24T14:00:28.013493Z 0 [Warning] [MY-010909] [Server] /usr/sbin/mysqld: Forcing close of thread 28user: 'root'.2023-12-24T14:00:29.246031Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.35-0ubuntu0.22.04.1)(Ubuntu).2023-12-24T14:01:51.652180Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.35-0ubuntu0.22.04.1) starting as process 141252023-12-24T14:01:51.662665Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.2023-12-24T14:01:52.129208Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.2023-12-24T14:01:52.441482Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.2023-12-24T14:01:52.441522Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.2023-12-24T14:01:52.485270Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock2023-12-24T14:01:52.485511Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.35-0ubuntu0.22.04.1'socket: '/var/run/mysqld/mysqld.sock'port: 3306(Ubuntu).
错误日志相关参数
log_error_services
Command-Line Format | –log-error-services=value |
---|---|
System Variable | log_error_services |
Scope | Global |
Dynamic | Yes |
SET_VAR Hint Applies | No |
Type | String |
Default Value | log_filter_internal; log_sink_internal |
参考:
log_error_services
https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_log_error_services
参考
27.12.21.2 The error_log Table
https://dev.mysql.com/doc/refman/8.0/en/performance-schema-error-log-table.html
5.4.2 The Error Log
https://dev.mysql.com/doc/refman/8.0/en/error-log.html
https://dev.mysql.com/doc/refman/8.0/en/log-file-maintenance.html