当前位置: 首页 > article >正文

mysqld.log文件过大,清理后不改变所属用户

#1024程序员节#

一、背景

突然有一天,我的mysql报磁盘不足了。仔细查看才发现,是磁盘满了。而MySQL的日志文件占用了91个G.如下所示:

[root@host-172-16-14-128 mysql]# ls -lrth
总用量 93G
-rw-r----- 1 mysql mysql 1.1G 730 2023 mysql-bin.000048
-rw-r----- 1 mysql mysql   68 730 2023 mysql-bin.index
-rw-r----- 1 mysql mysql  20K 129 11:49 mysql-error.log
-rw-r----- 1 mysql mysql 978K 129 11:57 slowquery.log
-rw-r----- 1 mysql mysql 868M 129 13:23 mysql-bin.000049
-rw-r----- 1 mysql mysql  91G 129 13:23 mysqld.log

二、解决

首先需要注意的是,如果日志文件很重要,是不建议直接处理的。应该先备份日志,再删除,从而获得空间。或者进行扩容操作!
我们尝试通过将日志写入"黑洞"中去。提示权限不够!其实是少写cat了,具体过程如下所示:

[root@host-172-16-14-128 mysql]# /dev/null >mysqld.log
-bash: /dev/null: 权限不够
[root@host-172-16-14-128 mysql]# whoami
root
[root@host-172-16-14-128 mysql]# 
[root@host-172-16-14-128 mysql]# su mysql
[root@host-172-16-14-128 mysql]# whoami
root
[root@host-172-16-14-128 mysql]# su - mysql
上一次登录:一 129 13:26:31 CST 2024pts/2 上
[root@host-172-16-14-128 mysql]# cat /dev/null >mysqld.log

操作完,我们看mysqld.log的大小已经变小了。

[root@host-172-16-14-128 mysql]# ls -lrth
总用量 1.9G
-rw-r----- 1 mysql mysql 1.1G 730 2023 mysql-bin.000048
-rw-r----- 1 mysql mysql   68 730 2023 mysql-bin.index
-rw-r----- 1 mysql mysql  20K 129 11:49 mysql-error.log
-rw-r----- 1 mysql mysql 978K 129 11:57 slowquery.log
-rw-r----- 1 mysql mysql  11K 129 13:27 mysqld.log
-rw-r----- 1 mysql mysql 868M 129 13:27 mysql-bin.000049

然后,我们再看看磁盘的情况,发现数据盘使用率为68%,已经降下来了。

[root@host-172-16-14-128 mysql]# df -h | grep dev
devtmpfs                                        3.9G     0  3.9G    0% /dev
tmpfs                                           3.9G     0  3.9G    0% /dev/shm
/dev/mapper/centos_host--172--16--14--128-root   35G  9.0G   27G   26% /
/dev/vdb1                                       300G  202G   99G   68% /data
/dev/vda1                                      1014M  194M  821M   20% /boot
[root@host-172-16-14-128 mysql]# 

END


http://www.kler.cn/news/368796.html

相关文章:

  • Golang Agent 可观测性的全面升级与新特性介绍
  • 实战OpenCV之深度学习
  • DICOM 基础知识:深入理解DICOM数据结构与标签说明
  • 入门 | Prometheus+Grafana 普罗米修斯
  • Spring-Day2
  • 基于去哪儿旅游出行服务平台旅游推荐网站【源码+安装+讲解+售后+文档】
  • c++设计通信类
  • react 总结+复习+应用加深
  • P11227 [CSP-J 2024] 扑克牌(民间数据)
  • 环 境 配 置
  • 【递归、回溯及搜索】No.4---综合练习
  • 【Spring MVC】请求参数的传递
  • 人工智能岗位英语面试 - 如何确保模型的可靠性和性能
  • wordpress伪静态规则
  • mongodb:增删改查和特殊查询符号手册
  • 安全边际篇
  • 【React】React 18:新特性与重大更新解析
  • Jenkins部署springboot项目 记录一下过程
  • LeetCode 107.二叉树的层次遍历 II
  • Flutter按钮控件(六)
  • 冒泡排序和二分查找--go
  • 报错解决:opene3d draw_geometries(): incompatible function arguments.
  • 智能工厂的设计软件 意识能力(被动综合/主动把握/折衷解决):意识形态及认知计算机科学的架构、系统和运用
  • Linux学习_7
  • C++学习路线(二十六)
  • Mysql 数据库架构