日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何查询MySql日志

發布時間:2025/3/20 编程问答 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何查询MySql日志 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天美國老板發來一封email,一句What happen to ...? 其他任何線索沒有,我的給出答案,一一排查,看能否找到問題緣由或是恢復數據,更新問題?程序問題?結果都是沒有頭緒,最后想了下mysql的日志看能否看看,以前沒看過mysql的日志,查查資料,最終皇天不負有心人,搞定了,現在總結下:

1.首先確認你日志是否啟用了

  • MySQL>show?variables?like?'log_bin';?
  • 2.如果啟用了,即ON那日志文件就在MySQL的安裝目錄的data目錄下

    3.怎樣知道當前的日志?

  • MySQL>?show?master?status;??
  • 4.看二進制日志文件用MySQLbinlog

  • shell>MySQLbinlog?mail-bin.000001?
  • 或者

  • shell>MySQLbinlog?mail-bin.000001?|?tail??
  • 因為mail-bin.000001是二進制的日志,所以想看日志就需要用mysqlbinlog命令,將二進制文件轉換為日志文件,下面詳細說說如何使用:上面已經說過如果啟用了日志文件,那么默認的日志文件就在data目錄下(如果你沒有更改的話)進入存放日志文件目錄,使用mysqlbinlog localhost-bin.000202 > new_file_name.log 命令,將目標文件保存為日志文件,可指定保存路徑下 有個小技巧跟大家介紹下,我在準備轉換的時候發現日志文件有2G多,尋思著為什么mysql為什么不把日志按日志定期的分多個文件放呢。結果發現mysql有個更好的方法,可以通過時間參數獲取某個時間段的數據,例子如下:mysqlbinlog ? --start-datetime="2010-11-20 00:00:00"? --stop-datetime="2010-11-21 00:00:00"?

    [hx@localhost data]$ mysqlbinlog mysqlbinlog Ver 3.0 for pc-linux-gnu at i686 By Monty and Sasha, for your professional use This software comes with NO WARRANTY: This is free software, and you are welcome to modify and redistribute it under 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 this database (local log only). -D, --disable-log-bin? Disable binary log. This is useful, if you enabled --to-last-log and are sending the output to the same MySQL server. This way you could avoid an endless loop. You would also like to use it when restoring after a crash to avoid duplication of the statements you already have. NOTE: you will 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 descriptors 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 having a datetime equal or posterior to the argument; the argument must be a date and time in the local time 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 use quotes for your shell to set it properly). --stop-datetime=name? Stop reading the binlog at first event having a datetime equal or posterior to the argument; the argument must be a date and time in the local time 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 use 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. Will not stop at the end of the requested binlog but rather continue printing until the end of the last binlog of the MySQL server. If you send the output to the same MySQL server, that may lead to an 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????????????????????????????? 3306 position????????????????????????? 4 read-from-remote-server?????????? FALSE open_files_limit????????????????? 64 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 檢查一個應用的問題的時候,發現通過?oracle 的 dblink 連接 mysql 進行更新等操作的時候,mysql 不會把操作的 sql 語句記錄到日志文件里,有點點郁悶了

    總結

    以上是生活随笔為你收集整理的如何查询MySql日志的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。