MySQL Forums
Forum List  »  Perl

Flush Logs - logging root access
Posted by: Adam McCormack
Date: June 03, 2008 01:42PM

I am having a difficult time developing a solution to Sarbanes Oxley requirements. What they are asking for is a log of root logins to the MySQL server, not what was done (which might actually be useful in case of a problem) only who (by IP) connected.

So Ive searched, and found the general log to have everything I need, however I can not leave it on, as our server will quickly run out of space.

I have a script that should find the root lines in the log, write them to another file, then clear the log file with the "FLUSH LOGS;" command, while trying to make it work though, I have had very intermittent results.

I have fiddled with the privileges, and I am not getting any error when running FLUSH LOGS from the command line (windows server 2003, MySQL 5.0.27-community-nt-log) however most of the time it does not clear the file. Just to frustrate me though, occasionally it does.

I am not working alone on the test environment, so I suspect that the problem is likely that other users are connected. I did however expect the flush to take place when they had completed their activities on the database, but this does not appear to be happening.

When logged in as root on the command line I try
mysql> flush logs;
Query OK, 0 rows affected (0.03 sec)
and nothing happens to the general log file, however the error log file is renamed with the .old extension, and a new error log is created, which madness, as I dont have the error log turned on.

do I just need to wait for a time when no one is connected, or is there some deeper trick I need to learn?
Thanks in advance for the help!

the salient portion of my script follows:

open (INFIL, "<$raw_log_file_name") || notify_error ("MySQL log file not found on $node", "file error");
open (OUTFILE, ">>$root_log_file_name") || notify_error ("Unable to write to MySQL root logfile on $node", "file error");
while (my $line = <INFIL>)
{
if ($line =~ m/root/)
{
print OUTFILE "$line";
}
}
close (INFIL);
my $sql_flush_logs = "flush logs;";
my $sth_flush_logs = $dbh->prepare($sql_flush_logs) || error_out("Could not prepare to flush the log in $scriptname: ".$DBI::errstr);
$sth_flush_logs->execute() || notify_error("Could not execute the log flush on $node", "in $scriptname: ".$DBI::errstr);
$sth_flush_logs->finish;
close (OUTFILE);
$dbh->disconnect;



Edited 2 time(s). Last edit at 06/03/2008 02:49PM by Adam McCormack.

Options: ReplyQuote


Subject
Written By
Posted
Flush Logs - logging root access
June 03, 2008 01:42PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.