Hello
I am using phpMyAdmin
Does anyone know whether phpMyAdmin logs operations done in the database?
Like who deleted entries? who added entries?
If so, where can such logs be found?
regards
logs in phpMyAdmin
Moderator: General Moderators
You can use MySQL binlog (binary logging facility) for this. Here is handy script to search through binlog for particular statements:
Code: Select all
#!/bin/php -q
<?php
set_time_limit(0);
$regexp = $argv[1];
if(!$regexp) {
die("DiE hard! You used this script in the wrong way.\n");
}
var_dump($regexp);
$logs = array();
if(empty($argv[2])) {
$logs = getLogs('binlog-bin.index');
} else {
$logs[] = basename($argv[2]);
}
if(strpos(end($logs), ",") !== false) {
$logs = explode(",", end($logs));
}
foreach($logs as $log) {
echo "=============$log=============\n";
foreach(grepFor($regexp, $log) as $query) {
echo $query . "\n\n";
}
}
function grepFor($regexp, $filename) {
$ret = array();
$current_query = '';
$fp = getLogPipe(basename($filename));
while(!feof($fp)) {
$line = trim(fgets($fp));
if(preg_match('/log_pos\s+(\d+)/', $line, $matches)) {
if(preg_match($regexp . 'm', $current_query)) {
$ret[] = $current_query;
}
$current_query = '';
} elseif(!preg_match('/^#/', $line)) {
$current_query .= "\n" . $line;
}
}
pclose($fp);
return $ret;
}
function getLogPipe($log) {
$fp = popen('mysqlbinlog ' . $log . ' 2>&1', 'r');
return $fp;
}
function getLogs($filename) {
return array_map(create_function('$name', 'return trim($name);'), file($filename));
}
function getUnprocessedLogs($logs) {
global $current_log;
$ret = $logs;
if(false !== ($index = array_search($current_log, $logs))) {
$ret = array_slice($logs, $index);
}
return $ret;
}
?>