diff -ur mysql-5.1.31/client/client_priv.h mysql-5.1.31-binlog/client/client_priv.h --- mysql-5.1.31/client/client_priv.h 2009-02-11 00:05:12.000000000 +0000 +++ mysql-5.1.31-binlog/client/client_priv.h 2009-02-10 22:52:14.000000000 +0000 @@ -80,5 +80,5 @@ OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT, OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE, OPT_WRITE_BINLOG, OPT_DUMP_DATE, - OPT_MAX_CLIENT_OPTION + OPT_MAX_CLIENT_OPTION, OPT_RAW_OUTPUT }; diff -ur mysql-5.1.31/client/mysqlbinlog.cc mysql-5.1.31-binlog/client/mysqlbinlog.cc --- mysql-5.1.31/client/mysqlbinlog.cc 2009-02-11 00:05:12.000000000 +0000 +++ mysql-5.1.31-binlog/client/mysqlbinlog.cc 2009-02-11 00:21:33.000000000 +0000 @@ -74,7 +74,7 @@ static const char* database= 0; static my_bool force_opt= 0, short_form= 0, remote_opt= 0; static my_bool debug_info_flag, debug_check_flag; -static my_bool force_if_open_opt= 1; +static my_bool force_if_open_opt= 1, raw_mode= 1; static ulonglong offset = 0; static const char* host = 0; static int port= 0; @@ -1010,6 +1010,9 @@ {"read-from-remote-server", 'R', "Read binary logs from a MySQL server", (uchar**) &remote_opt, (uchar**) &remote_opt, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"raw", OPT_RAW_OUTPUT, "Requires -R. Output raw binlog data instead of SQL statements", + (uchar**) &raw_mode, (uchar**) &raw_mode, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, + 0, 0}, {"result-file", 'r', "Direct output to a given file.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"server-id", OPT_SERVER_ID, @@ -1353,17 +1356,23 @@ Set safe delimiter, to dump things like CREATE PROCEDURE safely */ - fprintf(result_file, "DELIMITER /*!*/;\n"); - strmov(print_event_info.delimiter, "/*!*/;"); + if (!raw_mode) + { + fprintf(result_file, "DELIMITER /*!*/;\n"); + strmov(print_event_info.delimiter, "/*!*/;"); - print_event_info.verbose= short_form ? 0 : verbose; + print_event_info.verbose= short_form ? 0 : verbose; + } rc= (remote_opt ? dump_remote_log_entries(&print_event_info, logname) : dump_local_log_entries(&print_event_info, logname)); /* Set delimiter back to semicolon */ - fprintf(result_file, "DELIMITER ;\n"); - strmov(print_event_info.delimiter, ";"); + if (!raw_mode) + { + fprintf(result_file, "DELIMITER ;\n"); + strmov(print_event_info.delimiter, ";"); + } return rc; } @@ -1462,6 +1471,7 @@ { uchar buf[128]; ulong len; + uint header_count= 0; uint logname_len; NET* net; my_off_t old_off= start_position_mot; @@ -1586,8 +1596,23 @@ */ if (old_off != BIN_LOG_HEADER_SIZE) len= 1; // fake event, don't increment old_off + + if (raw_mode && (header_count == 0)) + { + header_count++; + fprintf(result_file,"%s", BINLOG_MAGIC); + } } - Exit_status retval= process_event(print_event_info, ev, old_off, logname); + + if (raw_mode) + { + fwrite(net->read_pos + 1, 1, len - 1, result_file); + } + else + { + Exit_status retval= process_event(print_event_info, ev, old_off, logname); + } + if (retval != OK_CONTINUE) DBUG_RETURN(retval); } @@ -1623,7 +1648,6 @@ DBUG_RETURN(OK_CONTINUE); } - /** Reads the @c Format_description_log_event from the beginning of a local input file. @@ -1973,27 +1997,30 @@ else load_processor.init_by_cur_dir(); - fprintf(result_file, + if (!raw_mode) + { + fprintf(result_file, "/*!40019 SET @@session.max_insert_delayed_threads=0*/;\n"); - if (disable_log_bin) - fprintf(result_file, + if (disable_log_bin) + fprintf(result_file, "/*!32316 SET @OLD_SQL_LOG_BIN=@@SQL_LOG_BIN, SQL_LOG_BIN=0*/;\n"); - /* - In mysqlbinlog|mysql, don't want mysql to be disconnected after each - transaction (which would be the case with GLOBAL.COMPLETION_TYPE==2). - */ - fprintf(result_file, + /* + In mysqlbinlog|mysql, don't want mysql to be disconnected after each + transaction (which would be the case with GLOBAL.COMPLETION_TYPE==2). + */ + fprintf(result_file, "/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE," "COMPLETION_TYPE=0*/;\n"); - if (charset) - fprintf(result_file, + if (charset) + fprintf(result_file, "\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;" "\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;" "\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;" "\n/*!40101 SET NAMES %s */;\n", charset); + } for (save_stop_position= stop_position, stop_position= ~(my_off_t)0 ; (--argc >= 0) ; ) @@ -2007,21 +2034,24 @@ start_position= BIN_LOG_HEADER_SIZE; } - /* - Issue a ROLLBACK in case the last printed binlog was crashed and had half - of transaction. - */ - fprintf(result_file, + if (!raw_mode) + { + /* + Issue a ROLLBACK in case the last printed binlog was crashed and had half + of transaction. + */ + fprintf(result_file, "# End of log file\nROLLBACK /* added by mysqlbinlog */;\n" "/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;\n"); - if (disable_log_bin) - fprintf(result_file, "/*!32316 SET SQL_LOG_BIN=@OLD_SQL_LOG_BIN*/;\n"); + if (disable_log_bin) + fprintf(result_file, "/*!32316 SET SQL_LOG_BIN=@OLD_SQL_LOG_BIN*/;\n"); - if (charset) - fprintf(result_file, + if (charset) + fprintf(result_file, "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n" "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n" "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n"); + } if (tmpdir.list) free_tmpdir(&tmpdir);