I am trying to recover the contents of a binary MySQL log file using PHP from the virtual machine I'm working with. I am running CentOS in a virtual machine and LAMP.
I have 4 virtual computers running on a virtual network, they are all located on the same subnet, and the MySQL databases are running and replication is working.
I am trying to recover the contents of the main buffer log using PHP. Typically, the contents of a file can be restored using the following command:
shell> mysqlbinlog [options] log_file
I wrote a PHP script that executes a shell command on the local computer:
$cmd="mysqlbinlog /var/lib/mysql/provider-bin.000003"; echo "<pre>".shell_exec($cmd);
I checked if provider-bin.000003 exists and that the shell_exec function works and is not disabled.
The problem occurs when I execute the command on the console, I get the contents of the bin file, but the PHP script does not display the expected result.
Instead, the following is displayed:
/*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @ OLD_COMPLETION_TYPE=@ @COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD _COMPLETION_TYPE*/;
Update: exec
I also tried using the exec function and it produces the same thing:
$cmd="mysqlbinlog /var/lib/mysql/provider-bin.000003"; print_r(exec($cmd,$ret_value)) . "<br />DONE"; echo "<pre>".shell_exec($cmd." 2>&1");
Very much appreciated
source share