今天美国老板发来一封email,一句What happen to ...? 其他任何线索没有,我的给出答案,一一排查,看能否找到问题缘由或是恢复数据,更新问题?程序问题?结果都是没有头绪,最后想了下mysql的日志看能否看看,以前没看过mysql的日志,查查资料,最终皇天不负有心人,搞定了,现在总结下:

1.首先确认你日志是否启用了

  1. MySQL>show variables like 'log_bin';

2.如果启用了,即ON那日志文件就在MySQL的安装目录的data目录下

3.怎样知道当前的日志

  1. MySQL> show master status;

4.看二进制日志文件用MySQLbinlog

  1. shell>MySQLbinlog mail-bin.000001

或者

  1. 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日志相关推荐

  1. 如何linux查看mysql目录下日志_测试人员如何在linux服务器中查询mysql日志?

    测试工程师在测试软件的过程中,流程往往是先接口测试,接着就是功能性测试.在做功能性测试的时候,往往有这么一个工作场景,就是出现错误后,我们怎么快速排除数据库报错. 举例某个电商网站,当我们文本框中输入 ...

  2. 查询mysql日志存储位置_查看mysql日志存放地点

    登录mysql终端 日志文件路径 mysql> show variables like 'general_log_file'; +------------------+------------- ...

  3. mysql 二进制日志查看_使用mysqlbinlog从二进制日志文件中查询mysql执行过的sql语句 (原)...

    前提 MySQL开启了binlog日志 操作 1. 查看MySQL是否开启binlog(进mysql操作) mysql> show variables like 'log_bin%'; 2. 查 ...

  4. MySQL日志文件之错误日志和慢查询日志详解

    今天天气又开始变得很热了,虽然很热很浮躁,但是不能不学习,我在北京向各位问好.今天给大家分享一点关于数据库日志方面的东西,因为日志不仅讨厌而且还很重要,在开发中时常免不了与它的亲密接触,就在前几天公司 ...

  5. mysql 开发进阶篇系列 41 mysql日志之慢查询日志

    一.概述 慢查询日志记录了所有的超过sql语句( 超时参数long_query_time单位 秒),获得表锁定的时间不算作执行时间.慢日志默认写入到参数datadir(数据目录)指定的路径下.默认文件 ...

  6. mysql日志存储类型_msyql 日志分类、存储、慢查询日志

    Mysql日志的分类: 出错日志(error log):(log_error)这个日志记载着服务器启动和关闭的情况,还记载着关于故障或异常状况的消息. 我们安装完数据库之后,启动数据库如果发生异常,我 ...

  7. MySQL日志(一)—— 慢查询日志slow log

    一.慢查询日志(slow log) 慢查询日志,就是查询超过一定的时间没有返回结果的时候,MySQL会将执行的SQL记录到日志中,这个日志,就称为慢查询日志.通过分析慢查询日志,可以快速找出执行慢的S ...

  8. wind mysql日志_Windows下的Mysql日志操作

    日志文件类型概述: 1. 错误日志 记录启动.运行或停止mysqld时出现的问题. My.ini配置信息: #Enter a name for the error log file. Otherwis ...

  9. python 数据库查询结果邮件提醒_Python实现的查询mysql数据库并通过邮件发送信息功能...

    本文实例讲述了Python实现的查询mysql数据库并通过邮件发送信息功能.分享给大家供大家参考,具体如下: 这里使用Python查询mysql数据库,并通过邮件发送宕机信息. Python代码如下: ...

最新文章

  1. 信息安全管理体系 ISMS
  2. world scientific is the journal to follow
  3. centos7配网卡_centos7配置网卡
  4. Java基础学习总结(24)——Java单元测试之JUnit4详解
  5. 前端学习(2452):封装数据接口
  6. NA-NP-IE系列实验28:HDLC 和PPP 封装
  7. android商城开源框架,Android商城开源项目--轻松购
  8. 【驱动】linux设备驱动·字符设备驱动开发
  9. Struts2 工作流程
  10. altium designer2020安装教程
  11. 基于opencv的实现简单的人脸识别功能
  12. 2019领克车展 Max Co币机诞生记
  13. 基于STM32F429IGT6的NAND FLASH读写测试(CUBEMX)
  14. jupyter notebook如何打开md文件
  15. ISCC 2021 SSTI
  16. 陆道培医疗冲刺香港上市:持续亏损,毛利率下滑,陆佩华为董事长
  17. iOS OC语言(二) 类
  18. 支持GIF动画的ImageView
  19. 破开C暗夜的第一道光(2)——高质量代码风格
  20. VTK 3D图像显示

热门文章

  1. 【pmcaff】纪录片:互联网时代(互联网人必读大片)
  2. PHP7 php_memcache.dll下载
  3. 基本数据与引用数据类型参数传递
  4. WPF入门教程系列三——Application介绍(续)
  5. Spring Boot -Shiro配置多Realm
  6. RXThink 官方网站正式上线
  7. Kubernetes安装之五:配置kubectl客户端
  8. 登录界面-安全密码设计
  9. 第十四章 springboot + profile(不同环境读取不同配置)
  10. JavaWeb显示器