Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a MySQL 5.5 service (RHEL 5.x) with a ~350Gb access log file. I'd like to zero this file out. Do I need to do anything special before-hand? Stop the server?

share|improve this question

closed as off-topic by mdpc, Katherine Villyard, Ward, Jenny D, Tim Brigham Mar 12 at 18:16

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance." – Ward, Tim Brigham
  • "Questions must be relevant to professional system administration. Server Fault is dedicated to professional system and network administrators. End user and enthusiast questions are off-topic (contact your system administrator or hire a professional to help you out). Please see the Help Center for more information." – mdpc, Katherine Villyard, Jenny D
If this question can be reworded to fit the rules in the help center, please edit the question.

3  
rename the file, use touch to create an empty file with the same name, permissions. Restart the server. –  Zoredache Mar 5 at 22:11

4 Answers 4

up vote 3 down vote accepted

First you rename the log file, then you issue the command FLUSH LOGS which causes MySQL to close and reopen the file. Since that file doesn't exist, it'll create a new one.

Then do whatever you want with the original file.

No restart necessary.

share|improve this answer
shell> cd mysql-data-directory
shell> mv mysql.log mysql.old
shell> mv mysql-slow.log mysql-slow.old
shell> mysqladmin flush-logs

refer to : MySQL :: MySQL 5.0 Reference Manual :: 5.2.5 Server Log Maintenance

share|improve this answer

What is access log in MySQL? You mean general_log? Anyway, rotate any MySQL log with logrotate. Here's sample config. Change log file names.

/root/.my.cnf must store user and password to connect to MySQL

# cat /etc/logrotate.d/mysql
/var/lib/mysql/mysql-error.log /var/lib/mysql/general.log {
    compress
    rotate 7
    size 1G
    missingok
    create 640 mysql mysql
    notifempty
    dateext
    sharedscripts
    postrotate
            test -x /usr/bin/mysqladmin || exit 0
            MYADMIN="/usr/bin/mysqladmin --defaults-file=/root/.my.cnf"
            if [ -z "`$MYADMIN ping 2>/dev/null`" ]; then
              if ps cax | grep -q mysqld; then
                exit 1
              fi 
            else
              $MYADMIN flush-logs
            fi
    endscript

}

share|improve this answer

cat /dev/null > your_access_log_file - No service restart required, but it will take a while to zero out 350GB

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.