How to limit mysql log files?

my debian.log file grows due to mysql errors which is located in /var/lib/mysql/debian.log …….. already edit the /etc/mysql/my.conf file sending the errors to / var / log / mysql / error.log with a size of 100M and expires after 10 days …….. the problem is that debian.log reached 270G and left me without space on the hard disk … …… I delete it and it recreates and grows …… I'm new to linode sorry :(

#general_log_file= /var/log/mysql/mysql.log
general_log= 1
# Error log - should be very few entries.
log_error = /var/log/mysql/error.log
# Here you can see queries with especially long duration
slow_query_log_file = /var/log/mysql/mysql-slow.log
slow_query_log= 1
long_query_time = 2
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id              = 1
log_bin                 = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
# * InnoDB
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!

2 Replies

@petterGil --

When you copy/paste from log/configuration files, you need to put the text between lines that consist of 3 backquotes (the character next to the '1' key)

like this

to turn off the Markdown processing of your text. Your config file entries are nearly unreadable otherwise ('#' is a marker character in Markdown).

That being said…

You can rotate/compress/delete your logs automagically with logrotate(8)…with automatic compression and automatic deletion of "old" logs. logrotate(8) is run automatically by cron(8). You can configure it by placing a configuration file for mysql in /var/log/logrotate.d. There's probably already one there so you just have to modify it (correctly).

See man logrotate for more information…

For example, this is what I use for /var/log/kern.log (which I'm assuming is the same as your /var/log/debian.log):

    rotate 6                      # keep 6 log files
    weekly                        # rotate weekly
    missingok                     # it's ok if the log file is empty

    notifempty                    # don't rotate if the log file is empty

    compress                      # compress after rotation (using gzip)

    delaycompress                 # delay compression (kern.log.1 will be
                                      # uncompressed while kern.log.2,3,4,5,6 will be
                                      # compressed)

    sharedscripts                 # a single script  may be  run multiple times for
                                      # log file entries which match multiple
                                      # files (such as /var/log/mail.*)

    postrotate                                # do this block AFTER rotation

    create 0644 root adm          # create the new log with this owner/permissions

I end up with this:

-rw-r--r-- 1 root adm  8021293 Oct 14 05:59 /var/log/kern.log
-rw-r--r-- 1 root adm 17349660 Oct 11 00:00 /var/log/kern.log.1
-rw-r--r-- 1 root adm  2251240 Oct  3 23:59 /var/log/kern.log.2.gz
-rw-r--r-- 1 root adm  2239675 Sep 26 23:59 /var/log/kern.log.3.gz
-rw-r--r-- 1 root adm  2428443 Sep 19 23:59 /var/log/kern.log.4.gz
-rw-r--r-- 1 root adm  2312863 Sep 12 23:59 /var/log/kern.log.5.gz
-rw-r--r-- 1 root adm  2070801 Sep  5 23:59 /var/log/kern.log.6.gz

-- sw

muchas gracias siempre se aprende algo nuevo :) .

Thank you very much you always learn something new :).


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct