how to query the MySQL logCategory: MySQL2012-02-23 19:14 26756 People read Comments (2) favorite reports Mysqlcommandprintingserversocketoutput
Today, the American boss sent an email, a word of what happen to ...? Any other clues do not, I give the answer, each to find out whether the cause of the problem or recover data, update the problem? A procedural problem? The results are no clue, and finally think of the next MySQL log to see if you can see, have not seen the log of MySQL, check the data, the final emperor is not a conscientious, done, and now summarized under:
1. First verify that your log is enabled
- MySQL>show variables like ' log_bin ';
2. If enabled, the on log file is in the data directory of the MySQL installation directory
3. How to know the current log
- MySQL> Show master Status;
4. Look at the binary log file with Mysqlbinlog
- Shell>mysqlbinlog mail-bin.000001
Or
- Shell>mysqlbinlog mail-bin.000001 | tail
Because mail-bin.000001 is a binary log, so want to see the log will need to use the Mysqlbinlog command, the binary file into a log file, the following details how to use: The above has said that if the log file is enabled, then the default log file is in the data directory (if you have not changed) into Store the log file directory, use the Mysqlbinlog localhost-bin.000202 > New_file_name.log command, save the destination file as a log file, you can specify the save path under a little trick to introduce you, I was ready to switch to find that the log file is more than 2G, wondering why MySQL does not log the logs on a regular basis in a number of files. It turns out that MySQL has a better way to get data for a certain time period through time parameters, such as: Mysqlbinlog--start-datetime= "2010-11-20 00:00:00"--stop-datetime= " 2010-11-21 00:00:00 "
[Email protected] data]$ Mysqlbinlog mysqlbinlog Ver 3.0 for Pc-linux-gnu @ i686 by Monty and Sasha, for your profession Al Use this software comes with NO warranty:this was free software, and you were welcome to modify and redistribute it unde R the GPL license
Dumps a MySQL binary log in a format usable for viewing or for piping to the MySQL command line client
Usage:mysqlbinlog [Options] log-files-d,--database=name List entries for just the database (local log only). -D,--disable-log-bin disable binary log. This is useful, if you have--to-last-log and is sending the output to the same MySQL server. This is the could avoid an endless loop. You would also if it is restoring after a crash to avoid duplication of the statements you already has. Note:you would need a SUPER privilege to use this option. -F,--force-read force reading unknown binlog events. -?,--help Display this help and exit. -H,--host=name Get the Binlog from server. -O,--offset=# Skip the first N entries. -p,--password[=name] password to connect to remote server. -p,--port=# use port to connect to the remote server. -j,--position=# Deprecated. Use--start-position instead. --protocol=name the Protocol of Connection (Tcp,socket,pipe,memory). -R,--result-file=name Direct output to a given file. -R,--read-from-remote-server read binary logs from a MySQL server--open_files_limit=# used to reserve file D Escriptors for usage by this program-s,--short-form Just Show the queries, no extra info. -S,--socket=name socket file to use for connection. --start-datetime=name start reading the Binlog at first event has a datetime equal or posterior to the argument; The argument must is a date and time in the local time zone, with any format accepted by the MySQL server for DATETIME and T Imestamp types, for example:2004-12-25 11:25:56 (you should probably use quotes for your shell to set it properly). --stop-datetime=name stop reading the Binlog at first event has a datetime equal or posterior to the argument; The argument must is a date and time in the localTime zone, in any format accepted by the MySQL server for DATETIME and TIMESTAMP types, for example:2004-12-25 11:25:56 ( You should probably with quotes for your shell to set it properly). --start-position=# start reading the binlog at position N. Applies to the first Binlog passed on the command line. --stop-position=# stop reading the binlog at position N. Applies to the last Binlog passed on the command line . -T,--to-last-log requires-r. Won't stop at the end of the requested Binlog but rather continue printing until the end of the last binlog of the MYSQ L server. If you send the output to the same MySQL server, the. Endless loop. -U,--user=name Connect to the remote server as username. -L,--local-load=name Prepare local temporary files for load DATA INFILE in the specified directory. -V,--version Print version and exit.
Variables (--variable-name=value) and Boolean options {false| TRUE} Value (after reading options)--------------------------------------------------------------database (No default value) disable-log-bin FALSE force-read FALSE host (No default value) offset 0 PORT&NBsp; 3306 position 4 read-from-remote-server FALSE Open_ files_limit short-form FALSE socket (No default value) start-datetime (No default value) stop-datetime (No default value) start-position 4 stop-position 18446744073709551615 to-last-log FALSE user (No default value) local-load (No default value)
2009.09.30 when checking for an application, MySQL does not log the operation's SQL statements to the journal file when it is updated with Oracle's Dblink connection, which is a bit depressing.
How to query the MySQL log