热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何查询MySql日志

如何查询MySql日志分类:mysql2012-02-2319:1426756人阅读评论(2)收藏举报mysqlcommandprintingserversocketoutput今
  如何查询MySql日志
分类: mysql
mysqlcommandprintingserversocketoutput

今天美国老板发来一封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日志


推荐阅读
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • 在project.properties添加#Projecttarget.targetandroid-19android.library.reference.1..Sliding ... [详细]
  • PDF内容编辑的两种小方法,你知道怎么操作吗?
    本文介绍了两种PDF内容编辑的方法:迅捷PDF编辑器和Adobe Acrobat DC。使用迅捷PDF编辑器,用户可以通过选择需要更改的文字内容并设置字体形式、大小和颜色来编辑PDF文件。而使用Adobe Acrobat DC,则可以通过在软件中点击编辑来编辑PDF文件。PDF文件的编辑可以帮助办公人员进行文件内容的修改和定制。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了指针的概念以及在函数调用时使用指针作为参数的情况。指针存放的是变量的地址,通过指针可以修改指针所指的变量的值。然而,如果想要修改指针的指向,就需要使用指针的引用。文章还通过一个简单的示例代码解释了指针的引用的使用方法,并思考了在修改指针的指向后,取指针的输出结果。 ... [详细]
author-avatar
D3LJ664D5LJ81111
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有