大网数据广告活动
服务器运维问答

Why /var/lib/mysql takes too much space whereas actual db is small enough

· 52CE 我爱测

In my server Db takes too much space: Filesystem Size Used Avail Use% Mounted on /dev/root 58G 58G 461M 100% / tmpfs 966M 0 966M 0% /dev/shm tmpfs 387M 856K 386M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock /dev/nvme0n1p15 105M 6.1M 99…

问题原文

原帖链接 · Dimitrios Desyllas · CC BY-SA 4.0

In my server Db takes too much space:

Filesystem       Size  Used Avail Use% Mounted on
/dev/root         58G   58G  461M 100% /
tmpfs            966M     0  966M   0% /dev/shm
tmpfs            387M  856K  386M   1% /run
tmpfs            5.0M     0  5.0M   0% /run/lock
/dev/nvme0n1p15  105M  6.1M   99M   6% /boot/efi
tmpfs            194M  4.0K  194M   1% /run/user/1000

And whilst I was investigating it I saw that /var/lib/mysql is the one who takes up the space:

ncdu 1.15.1 ~ Use the arrow keys to navigate, press ? for help                                                                                                                                                                                
--- /var/lib 
   50.6 GiB [##########] /mysql                                                                                                                                                                                                               
  801.2 MiB [          ] /snapd
  138.4 MiB [          ] /apt
   90.1 MiB [          ] /mecab
   39.4 MiB [          ] /dpkg
    3.8 MiB [          ] /ubuntu-advantage

And I tried to investigate what is the thing that takes too much space. All of the databases do serve wordpress site therefore I cannot modify the schema too much.

But I cheched the db size though:

SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;
+--------------------+--------------+
| Database           | Size (MB)    |
+--------------------+--------------+
| blog1              | 166.00000000 |
| information_schema |   0.00000000 |
| mysql              |   2.76562500 |
| performance_schema |   0.00000000 |
| blog2              |  31.79687500 |
| sys                |   0.01562500 |
+--------------------+--------------+
6 rows in set (0.35 sec)

Both of them Are relatively small Databases. Therefore how on Jesus' Christ name the /var/lib/mysql takes too much space?

The setup is just a LEMP stack with mysql without replication.

Edit 1

I have looked upon /var/lib/mysql and I see many records for binlog:

sudo du -sk /var/lib/mysql
53151572    /var/lib/mysql

$ sudo ls -l /var/lib/mysql | wc -l
623
# I susspect 653 lines would be too much if pasted here

$ sudo ls -l /var/lib/mysql | grep binlog | head
-rw-r----- 1 mysql mysql  43170892 Jun  4 00:00 binlog.000233
-rw-r----- 1 mysql mysql  35975939 Jun  5 00:00 binlog.000234
-rw-r----- 1 mysql mysql  36153241 Jun  6 00:00 binlog.000235
-rw-r----- 1 mysql mysql  37148526 Jun  7 00:00 binlog.000236
-rw-r----- 1 mysql mysql  34947871 Jun  8 00:00 binlog.000237
-rw-r----- 1 mysql mysql  34058129 Jun  9 00:00 binlog.000238
-rw-r----- 1 mysql mysql  36786212 Jun 10 00:00 binlog.000239
-rw-r----- 1 mysql mysql  34790230 Jun 11 00:00 binlog.000240
-rw-r----- 1 mysql mysql  37634381 Jun 12 00:00 binlog.000241
-rw-r----- 1 mysql mysql  35801131 Jun 13 00:00 binlog.000242

$ sudo ls -l /var/lib/mysql | grep binlog | wc -l
545

# 545 lines are binlog files therefore I have binlogs

And I have looked upon a way to mitigate it:

$ cat /etc/mysql/mysql.conf.d/rj.cnf
# Added by Rick James
[mysqld]
log_bin =                          # turn off
binlog_expire_logs_seconds = 86400  # 1 day
max_binlog_size = 1         # 100M

And I did:

mysql> SHOW BINARY LOGS;
PURGE BINARY LOGS BEFORE '2023-07-30 00:00:00';
Query OK, 0 rows affected, 1 warning (0.01 sec)

But still files keep filling up upon /var/lib/mysql Would be safe if I rm -rf them or if somehow could tell that binlog storage it /dev/null ?

已采纳解答

原帖链接 · Dimitrios Desyllas · CC BY-SA 4.0

In order to fix the issue do the following:

Remove the /etc/mysql/mysql.conf.d/rj.cnf

rm -rf /etc/mysql/mysql.conf.d/rj.cnf

Create a new config /etc/mysql/mysql.conf.d/no-binlog.cnf and add the follosing config:

[mysqld]
disable_log_bin

Then do:

sudo service mysql restart

Afterwards connect using the mysql command and run:

RESET MASTER

This will fix your issue. It is assumed that no replication is used for example having a single server that has a typical LAMP or LEMP stack. (eg personal server)


The reason why

The reason was that you had some logfiles that mysql uses upon replication. These logfiles are generated from binlog and can be accumulated over time.

In our approach we disable this type of logging due to lack of replication.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-07-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。