Page 1 of 1

logs in phpMyAdmin

Posted: Wed Mar 01, 2006 5:23 am
by jasongr
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

Posted: Wed Mar 01, 2006 9:10 am
by feyd
It doesn't log by default and I don't remember logging functions the last time I ran through the code (other than debug stuff for their code). From what I remember, logging would be a setting you tell MySQL to do.

Posted: Wed Mar 01, 2006 9:49 am
by Weirdan
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;
        }
?>

thanks

Posted: Wed Mar 01, 2006 9:57 am
by jasongr
I will read more about this stuff