Solved

How to do Log rotation and set max log file size policy in mysql ?

Posted on 2012-03-26
2
423 Views
Last Modified: 2012-04-11
I know how to enable log for mysql:
i insert the following line in /etc/my.cnf:
log=/datalogs/mysql.log

But how to configure mysql for log rotation and to set the max size for the same?

Is it possible to set that only teh update,insert and delete commands be logged ... i dont want to log select queries.
0
Comment
Question by:pvinodp
2 Comments
 
LVL 24

Accepted Solution

by:
johanntagle earned 500 total points
ID: 37768785
Use the binary logs (http://dev.mysql.com/doc/refman/5.1/en/binary-log.html) for logging only DML statements.  The log is not readily readable (it is binary) but it's easy to process using the mysqlbinlog utility.  An added benefit is you can use them to update a backup to point of failure in case you encounter problems (see http://dev.mysql.com/doc/refman/5.1/en/point-in-time-recovery.html).  

In you my.cnf:

log-bin = /path/to/where/you/want/your/logs/prefix

(everything after "log-bin" is optional.  documentation says "If no base_name value is given, the default name is the value of the pid-file option (which by default is the name of host machine) followed by -bin")

You set size limit via:

max_binlog_size = <size_in_bytes>

I don't know of an actual log rotation functionality in mysql, but you can set logs to expire via:

expire_logs_days = <number_in_days>

Hope this helps
0
 

Author Closing Comment

by:pvinodp
ID: 37836079
THanks for pointing to binary logs. Also you can set the database for which you need the logs for. This is helpful in case you have multiple database in your mysql server.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question