当前位置:网站首页>MySQL 日志错误日志
MySQL 日志错误日志
2022-07-27 17:56:00 【华为云】
28.3 错误日志
MySQL的错误日志中记录了MySQL运行过程中的所有出错信息,查看MySQL的错误日志能够帮助数据库维护人员更好地排查MySQL服务器的故障。
28.3.1 开启错误日志
可以在my.cnf文件或者my.ini文件中配置开启错误日志功能。
[mysqld]log_error = /data/mysql/log/error_log/mysql-error.log其中,log_error表示错误日志文件的位置。如果没有为log_error赋值,则MySQL默认会在DATADIR指定的目录(MySQL的数据存放目录)下创建一个host_name.err文件来记录MySQL的错误日志。
配置成功后,需要重新开启MySQL服务器才能生效。
注意:MySQL不支持在MySQL命令行执行如下命令开启错误日志。
mysql> SET GLOBAL log_error = '/data/mysql/log/error_log/mysql-error.log';ERROR 1238 (HY000): Variable 'log_error' is a read only variable重新启动MySQL服务器后,查看/data/mysql/log/error_log目录下的文件。
[[email protected] ~]# ll /data/mysql/log/error_log/total 4-rw-r----- 1 mysql mysql 354 Jan 17 14:22 mysql-error.log结果显示,data/mysql/log/error_log目录下已经成功生成了mysql-error.log文件。
28.3.2 查看错误日志
MySQL的错误日志文件是以纯文本文件的格式存储到服务器的磁盘上,可以直接查看文件的内容。
(1)向t_goods_category数据表中插入数据,并使SQL语句报错。
mysql> INSERT INTO t_goods_category -> (id, t_category) -> VALUES -> ('mysql', 'mysql');ERROR 1366 (HY000): Incorrect integer value: 'mysql' for column 'id' at row 1(2)查看MySQL错误日志文件。
cat /data/mysql/log/error_log/ mysql-error.log################省略n行日志#######################2020-01-17T07:02:53.958135Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.112020-01-17T07:02:53.959012Z 0 [Note] InnoDB: Number of pools: 12020-01-17T07:02:53.960377Z 0 [Note] InnoDB: Not using CPU crc32 instructions2020-01-17T07:02:53.966535Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M2020-01-17T07:02:53.977288Z 0 [Note] InnoDB: Completed initialization of buffer pool2020-01-17T07:02:54.060328Z 0 [Note] InnoDB: Highest supported file format is Barracuda.2020-01-17T07:02:56.286598Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.2020-01-17T07:02:56.287290Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.2020-01-17T07:02:56.288285Z 0 [Note] InnoDB: Waiting for purge to start28.3.3 删除错误日志
MySQL的错误日志也可以像查询日志和慢查询日志一样直接删除,如果需要重新生成日志文件,则在MySQL命令行执行FLUSH LOGS命令,在服务器命令行执行mysqladmin flush-logs命令。
(1)删除错误日志。
rm -rf /data/mysql/log/error_log/mysql-error.log查看/data/mysql/log/error_log/目录下的文件。
[[email protected] ~]# ll /data/mysql/log/error_log/total 0结果显示,mysql-error.log文件已经被删除。
(2)刷新日志文件。
mysql> FLUSH LOGS; Query OK, 0 rows affected (0.01 sec)或者在服务器命令行执行如下命令刷新日志。
[[email protected] ~]# mysqladmin -uroot -p flush-logsEnter password:再次查看/data/mysql/log/error_log/目录下的文件。
[[email protected] ~]# ll /data/mysql/log/error_log/total 4-rw-r----- 1 mysql mysql 354 Jan 17 15:18 mysql-error.log刷新日志后,MySQL会重新生成错误日志文件。
28.3.4 关闭错误日志
关闭MySQL的错误日志,只需要将my.cnf文件或者my.ini文件中的log_error配置项删除,并重新开启MySQL即可。读者可自行实践,这里不再赘述。
边栏推荐
- Office automation solution - docuware cloud is a complete solution to migrate applications and processes to the cloud
- JVM overview and memory management (to be continued)
- 继华为、联发科之后,这家手机芯片厂商宣布向武汉捐款700万
- PyQt5快速开发与实战 4.3 QLabel and 4.4 文本框类控件
- PyQt5快速开发与实战 4.5 按钮类控件 and 4.6 QComboBox(下拉列表框)
- Codeforces Round #810 (Div. 2)B.party(思维题)超详细题解
- Graphic leetcode - Sword finger offer II 115. reconstruction sequence (difficulty: medium)
- [RCTF2015]EasySQL-1|SQL注入
- Pyqt5 rapid development and practice 4.5 button controls and 4.6 qcombobox (drop-down list box)
- Common methods of object learning [clone and equals]
猜你喜欢

Data warehouse construction - DWD floor

PyQt5快速开发与实战 4.3 QLabel and 4.4 文本框类控件

十年测试老鸟聊聊移动端兼容性测试

Pyqt5 rapid development and practice 4.5 button controls and 4.6 qcombobox (drop-down list box)

JS实现视频录制-以Cesium为例

Idea: solve the problem of code without prompt

You can understand it at a glance, eslint

Learn about the 12 necessary animation plug-ins of blender

技术分享 | 接口自动化测试中,如何做断言验证?

Technology sharing | how to do Assertion Verification in interface automated testing?
随机推荐
Conversion of Oracle date
发布2年后涨价100美元,Meta Quest 2的逆生长
Huawei's 150 member team rushed to the rescue, and Wuhan "Xiaotangshan" 5g base station was quickly opened!
华为150人团队驰援,武汉“小汤山”5G基站火速开通!
Office automation solution - docuware cloud is a complete solution to migrate applications and processes to the cloud
Huawei's mobile phone shipments exceed Apple's, ranking second in the world, but it faces a large amount of inventory that needs to be cleaned up
Learn about the 12 necessary animation plug-ins of blender
Unity2d dynamic cartoon script (animation demonstration II for the chapter of Tiger Bridge)
Zepto入门详解
If you want to switch to software testing, you should pass these three tests first, including a 3000 word super full test learning guide
速卖通:按关键字搜索商品 API
Oracle simple advanced query
Assignment 1 - Hello World ! - Simple thread Creation
Redis Hash 结构命令
OA项目之我的审批(查询&会议签字)
Illustration leetcode - 592. Fraction addition and subtraction (difficulty: medium)
PyQt5快速开发与实战 4.3 QLabel and 4.4 文本框类控件
LG集团宣布将向湖北捐赠300万元现金、120万个口罩、1万套防护服
Built in functions other functions
JD: search product API by keyword